PageSpeed Insights complains about Nginx+PageSpeed

292 views
Skip to first unread message

Tomasz Ciborski

unread,
Jan 20, 2015, 10:07:39 AM1/20/15
to mod-pagesp...@googlegroups.com
Hi folks

This is a continuation of the discussion from pagespeed-insights-discuss at https://groups.google.com/forum/#!topic/pagespeed-insights-discuss/4HIRtTHVsAE .

Quote:
"I'm optimizing a website using Nginx+Pagespeed and I use the defer_javascript feature. When I run the site through PageSpeed it complains that the site needs to Eliminate render-blocking JavaScript and CSS in above-the-fold content with the file /pagespeed_static/js_defer.eX_CQDtaZA.js. Funny enough, this is the file autogenerated by the PageSpeed nginx plugin. How would I go about fixing this? I can't find an option to make the auto-generated JS file a deferred or async load? 
The score on my client's website used to be 90+ on both mobile and web. Now with the new metrics in place, it hovers around 70/85. The site: www . rksv . in"
End of quote.

I have the same issue with the latest PSM ngx_pagespeed-release-1.9.32.3-beta running at Nginx (full) 1.6.2-5. It adds http://santelab.pl/pagespeed_static/js_defer.pbrP1whUgE.js file on which Pagespeed Insights complain (picture attached psm_e.png).

This is what Miguel García Sánchez - Colomer suggested
Quote:
<script type="text/javascript">
function downloadJSAtOnload() {
var element = document.createElement("script");
element.src = "/pagespeed_static/js_defer.eX_CQDtaZA.js";
document.body.appendChild(element);
}
if (window.addEventListener)
window.addEventListener("load", downloadJSAtOnload, false);
else if (window.attachEvent)
window.attachEvent("onload", downloadJSAtOnload);
else 
window.onload = downloadJSAtOnload;
</script>
Or if it's possible and don't need to be deferred you can make it async:

<script type='text/javascript'>
(function(){
var bsa = document.createElement('script');
bsa.type = 'text/javascript';
bsa.async = true;
bsa.src = '/pagespeed_static/js_defer.eX_CQDtaZA.js';
(document.getElementsByTagName('head')[0]||document.getElementsByTagName('body')[0]).appendChild(bsa);
})();
</script>

or this async way:

<script type='text/javascript'> (function(){ var s=document.createElement('script'); s.type='text/javascript'; s.async=true; s.src='/pagespeed_static/js_defer.eX_CQDtaZA.js'; var h=document.getElementsByTagName('script')[0]; h.parentNode.insertBefore(s,h); })();  </script>
End of quote

The website is available at http://santelab.pl/. You can add query parameters to inspect raw html code http://santelab.pl/?ModPagespeed=off .
PSM config attached (psm.txt).

Tom
psm_e.png
psm.txt

Jeff Kaufman

unread,
Jan 21, 2015, 9:14:02 AM1/21/15
to mod-pagespeed-discuss
When I look at PageSpeed insights for your domain it's not objecting
to /pagespeed_static/js_defer...js but to /_,Mjo...js This is a file
created with javascript outlining. What happens if you turn off
outline_javascript? When I turn it off with a query param, by going
to http://santelab.pl/?PageSpeedFilters=-outline_javascript I don't
see Insights complaining about blocking js anymore:
https://developers.google.com/speed/pagespeed/insights/?url=http%3A%2F%2Fsantelab.pl%2F%3FPageSpeedFilters%3D-outline_javascript
> --
> You received this message because you are subscribed to the Google Groups
> "mod-pagespeed-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mod-pagespeed-di...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mod-pagespeed-discuss/7d73041b-30ab-453c-a109-754ea1eb53db%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Tomasz Ciborski

unread,
Jan 21, 2015, 12:31:30 PM1/21/15
to mod-pagesp...@googlegroups.com
Hi Jeff

First of all, thanks for your help. It very works well with your suggestion.

It is confusing at first because PSI complains on either js_defer.. you mentioned or on _,xxx JS file depending on how many times you test the website. 

Have a nice day

Best
Tom
Reply all
Reply to author
Forward
0 new messages