Skip to content
This repository has been archived by the owner on Oct 17, 2020. It is now read-only.

Commit

Permalink
Merge pull request #632 from liferay/wincent/preload
Browse files Browse the repository at this point in the history
feat(css-loader): use preload when available (#631)
  • Loading branch information
wincent authored Aug 28, 2020
2 parents 1872a89 + 1423ca3 commit 2e78152
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,24 @@
exports[`java projects correctly generates JS module 1`] = `
"
var link = document.createElement(\\"link\\");
link.setAttribute(\\"rel\\", \\"stylesheet\\");
var preload;
try {
preload = link.relList.supports(\\"preload\\");
}
catch (error) {
preload = false;
}
if (preload) {
link.setAttribute(\\"as\\", \\"style\\");
link.setAttribute(\\"rel\\", \\"preload\\");
}
else {
link.setAttribute(\\"rel\\", \\"stylesheet\\");
}
link.setAttribute(\\"type\\", \\"text/css\\");
link.setAttribute(\\"href\\", Liferay.ThemeDisplay.getPathContext() + \\"/o/java-project/file.css\\");
Expand Down Expand Up @@ -32,7 +49,24 @@ module.exports = link;
exports[`standard projects correctly generates JS module 1`] = `
"
var link = document.createElement(\\"link\\");
link.setAttribute(\\"rel\\", \\"stylesheet\\");
var preload;
try {
preload = link.relList.supports(\\"preload\\");
}
catch (error) {
preload = false;
}
if (preload) {
link.setAttribute(\\"as\\", \\"style\\");
link.setAttribute(\\"rel\\", \\"preload\\");
}
else {
link.setAttribute(\\"rel\\", \\"stylesheet\\");
}
link.setAttribute(\\"type\\", \\"text/css\\");
link.setAttribute(\\"href\\", Liferay.ThemeDisplay.getPathContext() + \\"/o/a-project/file.css\\");
Expand Down
19 changes: 18 additions & 1 deletion packages/liferay-npm-bundler-loader-css-loader/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,24 @@ export default function(
// returns both pathProxy and the context path of the portal's webapp.
context.extraArtifacts[`${filePath}.js.wrap-modules-amd.template`] = `
var link = document.createElement("link");
link.setAttribute("rel", "stylesheet");
var preload;
try {
preload = link.relList.supports("preload");
}
catch (error) {
preload = false;
}
if (preload) {
link.setAttribute("as", "style");
link.setAttribute("rel", "preload");
}
else {
link.setAttribute("rel", "stylesheet");
}
link.setAttribute("type", "text/css");
link.setAttribute("href", Liferay.ThemeDisplay.getPathContext() + "${href}");
Expand Down

0 comments on commit 2e78152

Please sign in to comment.