incubator-pagespeed-ngx icon indicating copy to clipboard operation
incubator-pagespeed-ngx copied to clipboard

Duplicated javascript files loading in browser based on Chrome

Open vanushwashere opened this issue 4 years ago • 9 comments

I found out that if we enable defer_javascript or lazyload_images filtres, some of the JS files on the website load twice. I checked that on Firefox and didn't get the same result, so I assume that this is Chromium-based browsers' behavior. Also, I found out this bug https://github.com/apache/incubator-pagespeed-mod/issues/1054 which I think is related to this.

vanushwashere avatar Sep 03 '20 10:09 vanushwashere

It load twice the exact same file? or load 1 time the file and 1 time the rewrited by pagespeed url?

Lofesa avatar Sep 03 '20 19:09 Lofesa

Second option: first the PageSpeed rewritten file then the original file.

vanushwashere avatar Sep 03 '20 20:09 vanushwashere

Can you verify if you have a link header to preload the asset? Pagespeed don´t rewrite headers, so if you have it then you have 1st the header and 2nd the html, this last is rewrited by pagespeed and are not the same file name, but had the same content.

Lofesa avatar Sep 04 '20 09:09 Lofesa

https://strongboxtechnology.10web.cloud/ here is the website, as you can see it loads wp-content/cache/tw_optimize/js/two_07f45a878040049d26642d9ad2754c36.js.pagespeed.jm.jNGuvHpZaz.js and wp-content/cache/tw_optimize/js/two_07f45a878040049d26642d9ad2754c36.js. If you open https://strongboxtechnology.10web.cloud/?PageSpeed=off you'll see that there is only one load of that file.

vanushwashere avatar Sep 04 '20 10:09 vanushwashere

I think the issue is not related to pagespeed module but other plugin you have. Some plugin (maybe other way) put files as a link preload header, that is rewrited (have the pagespeed stuf in it) but in the html the file get untouched by pagespeed because it have <!--This script contains introspective JavaScript and is unsafe to replace.--> Same thing occurs with your jquery.js, but in this case both files (header link and html code) are the same (with pagespeed stuff in it) You may avoid this with: pagespeed AvoidRenamingIntrospectiveJavascript off; but this can cause problems. Or can avoid this file to be pushed as a link header and then only load the file in the html code.

Captura

Captura

Lofesa avatar Sep 04 '20 11:09 Lofesa

image But there is no preloaded js with disabled PageSpeed module.

vanushwashere avatar Sep 22 '20 13:09 vanushwashere

There is something wrong with hint_preload_subresource the issue is gone when I disable that filter

vanushwashere avatar Sep 22 '20 13:09 vanushwashere

This filter (hint_preload_subresource), when work (I've never gotten it to work), create the preload header, maybe the filter creates it with the rewrited url, but latter the filter rewrite_javascript can´t rewrite the url in the html because is unsafe to change, this make downlod the same file 2 times, one rewrited and other w/o rewrite.

Lofesa avatar Sep 22 '20 13:09 Lofesa

Yep, I also think so

vanushwashere avatar Sep 22 '20 13:09 vanushwashere