-
Notifications
You must be signed in to change notification settings - Fork 155
defer_js loads javascript twice #1054
Comments
I encountered this while using IISpeed and was able to prevent some third party resources (jscache.com & tripadvisor.com) from being loaded twice by adding the "Disallow" directive.
We use a CMS, so it would be difficult to identify and add all third-party rules as directives to the config file. Previously adding pagespeed_no_defer="" to scripts and resources was enough, but this seems to be ignored. (As a result, we've disabled "defer" features altogether.) I use the options to combine JS & CSS. I had to disable "InPlaceResourceOptimization". It would correctly combine original files into a single file and then additionally call the original file separately. |
Moved blank js issue to #1325, since it turns out not to be related. |
Took a packet capture of chrome talking to a "frozen" copy of this (pagespeed not running, just pagespeed's output) with tcpdump. I see:
(This matches what chrome reports in the network tab in developer tools.) Note that the first requests for example1 and example2 go out before js_defer has even been requested, which suggests that labeling with Here's the packet capture (gzip manually disabled on the server): |
To test this, I made a simple page with no defer javascript at all:
Loading this with chrome, example1 and example2 still gets fetched, presumably by the preload scanner since they don't get run. WPT agrees. packet capture: current4.txt |
My current hypothesis is that we're getting triple loads because:
|
To test this, I modified defer_js:
Now I see:
This is consistent with the hypothesis, since with image-based preloading available only did one load of each js file after running defer-js instead of two. packet capture: no-image-prefetch.txt |
What's not clear to me is why Chrome would make three requests for the same url, instead of re-using what's in its cache. Why would you want a preload scanner to throw away its results? |
I'm also not sure whether we want to thwart the preload scanner here. The reason to thwart it is that because we're deferring the execution of the js the browser is wrong to heavily prioritize loading it since it won't actually be blocking things. The reason not to thwart it is that simply loading the js isn't that bad, we want to preload it somehow anyway, and for page loading the important thing is keeping the incoming pipe full. |
I had thought that maybe the preload scanner results getting re-fetched was because we were using different headers, but diffing them they are both exactly:
|
I want to get a simple repro case for the preload scanner so I can talk to chromium and figure out if it's a bug, but my first try failed to trigger a duplicate load:
capture: repro1.txt |
(@crowell just checked, and firefox doesn't see either kind of duplicate load) |
The preload scanner duplicate load doesn't happen in safari. packet capture: safari4.txt |
It looks like two things are going on:
We can easily fix (1) ourselves. I've posted on net-dev@chromium to figure out if (2) is something we can get fixed in Chrome: https://groups.google.com/a/chromium.org/forum/#!topic/net-dev/PpITTXI7VVs |
As requested on net-dev, filed a crbug: https://bugs.chromium.org/p/chromium/issues/detail?id=623109 |
In debugging this with the Chromium folks they pointed out that these scripts should be loaded from cache, and the extra network loads only happen when you disable the cache. The cache is disabled if you use As long as you're running normally, without disabling the cache, this shouldn't cause any additional network loads in practice. My guess at this point is that all the results that did show network loads were results run with |
We could "fix" this by using |
Planning to start adding |
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
Hi, I have the same issue, when we can get the update? |
Original issue reported on code.google.com by
jefftk@google.com
on 19 Mar 2015 at 4:41The text was updated successfully, but these errors were encountered: