Permalink
Browse files

preloading: switch defer_js to rel=preload

defer_js was using Image objects to preload scripts for WebKit in a way that is
harmful in modern browsers.  Currently this isn't actually needed in Chrome,
since the preload scanner already finds our deferred scripts, but Chrome is
thinking of removing that [1].  This change switches us to the new standard,
rel=preload, which we will need once Chrome updates its scanner not to preload
things with invalid type attributes.

Fixes #1054

[1] https://bugs.chromium.org/p/chromium/issues/detail?id=623109
  • Loading branch information...
crowell committed Jul 25, 2016
1 parent d1972f6 commit e2aa6f4f75442770c373e6ce3694dbbb5a9313c3
@@ -130,7 +130,11 @@ deferJsNs.DeferJs.prototype.createIdVars = function() {
b && (a = this.globalEval(b), a.setAttribute(deferJsNs.DeferJs.PSA_NOT_PROCESSED, ""), a.setAttribute(deferJsNs.DeferJs.PRIORITY_PSA_NOT_PROCESSED, ""));
};
deferJsNs.DeferJs.prototype.attemptPrefetchOrQueue = function(a) {
this.isWebKit() && ((new Image).src = a);
var b = this.origCreateElement_.call(document, "link");
b.setAttribute("rel", "preload");
b.setAttribute("as", "script");
b.setAttribute("href", a);
document.head.appendChild(b);
};
deferJsNs.DeferJs.prototype.addNode = function(a, b, c) {
var d = a.getAttribute(deferJsNs.DeferJs.PSA_ORIG_SRC) || a.getAttribute("src");
@@ -609,7 +613,7 @@ deferJsNs.deferInit = function() {
deferJsNs.deferInit();
pagespeed.deferJsStarted = !1;
deferJsNs.startDeferJs = function() {
pagespeed.deferJsStarted || pagespeed.panelLoader || (pagespeed.deferJsStarted = !0, pagespeed.deferJs.registerScriptTags(), pagespeed.deferJs.execute());
pagespeed.deferJsStarted || (pagespeed.deferJsStarted = !0, pagespeed.deferJs.registerScriptTags(), pagespeed.deferJs.execute());
};
deferJsNs.startDeferJs = deferJsNs.startDeferJs;
pagespeedutils.addHandler(document, "DOMContentLoaded", deferJsNs.startDeferJs);
Oops, something went wrong.

0 comments on commit e2aa6f4

Please sign in to comment.