Skip to content
This repository has been archived by the owner on Apr 21, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
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 e2aa6f4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 30 deletions.
8 changes: 6 additions & 2 deletions net/instaweb/genfiles/rewriter/js_defer_dbg.js
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit e2aa6f4

Please sign in to comment.