apache / incubator-pagespeed-ngx

Automatic PageSpeed optimization module for Nginx
http://ngxpagespeed.com/
Apache License 2.0
4.37k stars 363 forks source link

Missing <body> tag? #835

Open pdufour opened 9 years ago

pdufour commented 9 years ago

Hey, it could very well be an issue with our application, but I wanted to raise it here in case other people have experienced it. I'm having problems where every once in a while there will be a response from a page with no <body> tag in it.

...
<link rel="apple-touch-icon" sizes="114x114" href="/apple-touch-icon-precomposed-144x144.png">
<script type="text/javascript" pagespeed_no_defer="" src="//pixel.brit.co/wp-content/themes/britco-responsive/js/head.js?ver=2.5.0-www-brit-co"></script><script type="text/javascript">var sranalytics={"version":"0.1.3","pid":"516705b24240cf91820000ad","iframe":"0","title":"This Gadget Will Turn Off Your Lights from Around the World","url":"http:\/\/www.brit.co\/newbeem\/","date":"2014-10-21 20:20:41","channels":["tech"],"tags":["Gadgets","home gadget","Kickstarter","lights","newbeem"</script>
</head>
</html>

Full HTML here: https://gist.github.com/pdufour/a1070be8076fee63a812

The one thing that made me think it might be a Pagespeed problem was the fact that the SR analytics script block was cut off. So maybe the minifier is encountering some error that's causing the issue. The whole block should read:

<script type='text/javascript'>var sranalytics={"version":"0.1.3","pid":"516705b24240cf91820000ad","iframe":"0","title":"This Gadget Will Turn Off Your Lights from Around the World","url":"http:\/\/www.brit.co\/newbeem\/","date":"2014-10-21 20:20:41","channels":["tech"],"tags":["Gadgets","home gadget","Kickstarter","lights","newbeem","outlet","smart outlet","smartphone gadget"],"authors":["Lesley Lewis"]};</script>

Edit: Looking back through the other times it's happened.. whenever there is a missing <body> tag, there is a cut off <script> block as well. So there must be some correlation between the two.

Edit 2: The test url, for reference, http://www.brit.co/newbeem

oschaaf commented 9 years ago

@pdufour How often is that happening? Do you have more information? It doesn't seem to be happening for me, but perhaps it only occurs when using another user-agent, or I'm missing some other precondition for the problem to occur.

If you are able to reproduce it reliably: Does it still happen when you have pagespeed off; in nginx.conf?. If not, does it happen when you have pagespeed RewriteLevel PassThrough; configured?

pdufour commented 9 years ago

It happens every so often @oschaaf. I think I found the culprit, though. https://developers.facebook.com/bugs/611981358913201/. Facebook seems to be only fetching the first portion of the page, and since I had a big inline script caused by the inline_javascript filter, it doesn't reach the <meta> tags. So I just fixed it by moving the meta tags above any scripts.

So even though Pagespeed is not the culprit directly, I wonder if it would make sense to make a note in the docs https://developers.google.com/speed/pagespeed/module/filter-js-inline, as it took me a super long time to figure that out. Might be useful for some other people who run into the problem.

And another solution would be to have a filter for moving meta tags about CSS and scripts, similar to https://developers.google.com/speed/pagespeed/module/filter-css-above-scripts

oschaaf commented 9 years ago

@pdufour thanks for the feedback. Could you add an example documentation fragment of what would be useful to illustrate?

As for the meta-tags: could you file an issue for that?: https://code.google.com/p/modpagespeed/issues/list