Skip to content

Commit 957f0a1

Browse files
authored
Merge pull request #18933 from mozilla/FXA-11759
fix(perf): change css link tag's initial rel attr to preload
2 parents 730e4bd + d9b481f commit 957f0a1

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

packages/fxa-settings/config/webpack.config.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,33 @@ module.exports = function (webpackEnv) {
664664
filename: 'static/css/[name].[contenthash:8].css',
665665
chunkFilename: 'static/css/[name].[contenthash:8].chunk.css',
666666
}),
667+
isEnvProduction &&
668+
new (class {
669+
apply(compiler) {
670+
compiler.hooks.compilation.tap(
671+
'LinkTagRewritePlugin',
672+
(compilation) => {
673+
HtmlWebpackPlugin.getHooks(compilation).alterAssetTagGroups.tap(
674+
'LinkTagRewritePlugin',
675+
(data) => {
676+
data.headTags.forEach((tag) => {
677+
if (
678+
tag.tagName === 'link' &&
679+
tag.attributes.rel === 'stylesheet'
680+
) {
681+
tag.attributes.rel = 'preload';
682+
tag.attributes.as = 'style';
683+
tag.attributes.onload =
684+
"this.onload=null; this.rel='stylesheet';";
685+
tag.attributes.crossorigin = 'anonymous';
686+
}
687+
});
688+
}
689+
);
690+
}
691+
);
692+
}
693+
})(),
667694
// Generate an asset manifest file with the following content:
668695
// - "files" key: Mapping of all asset filenames to their corresponding
669696
// output file so that tools can pick it up without having to parse

0 commit comments

Comments
 (0)