Skip to content

Commit

Permalink
Load plugin styles async on load (#1176)
Browse files Browse the repository at this point in the history
  • Loading branch information
jharwig authored and mwizeman committed Jun 9, 2017
1 parent cadc86d commit 139807a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions web/war/src/main/webapp/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />

<link href='css/visallo.css' rel='stylesheet' media='screen'>
<noscript id="deferred-styles">
{{#each pluginCssResources}}<link href='{{contextPath}}/{{.}}' rel='stylesheet' media='screen'>
{{/each}}
</noscript>

<script src='libs/babel-polyfill/dist/polyfill.min.js'></script>
<script src='jsc/require.config.js'></script>
Expand Down Expand Up @@ -40,6 +42,22 @@
{{#each pluginJsResourcesWebWorker}} '{{contextPath}}{{.}}'{{#unless @last}},{{/unless}}
{{/each}}]
};
var loadDeferredStyles = function() {
var addStylesNode = document.getElementById("deferred-styles");
if (addStylesNode) {
var replacement = document.createElement("div");
replacement.innerHTML = addStylesNode.textContent;
document.body.appendChild(replacement)
addStylesNode.parentElement.removeChild(addStylesNode);
}
};
var raf = requestAnimationFrame || mozRequestAnimationFrame || webkitRequestAnimationFrame || msRequestAnimationFrame;
if (raf) {
raf(function() { window.setTimeout(loadDeferredStyles, 0); });
} else {
window.addEventListener('load', loadDeferredStyles);
}
})();
</script>
<script data-main="visallo" src='libs/requirejs/require.js'></script>
Expand Down

0 comments on commit 139807a

Please sign in to comment.