Re: Strange behavior on http://modpagespeed.com/defer_javascript.html

17 views
Skip to first unread message

Joshua Marantz

unread,
Oct 15, 2012, 9:28:15 PM10/15/12
to mod-pagespeed-discuss
defer_javascript is user-agent sensitive -- it won't work on all browsers.   So if you are fetching from modpagespeed.com without one set, the filter will automatically turn itself off.

To test it from a script, set the UA to the same one used in Chrome, which you can find with something like http://whatsmyuseragent.com/.

-Josh


On Mon, Oct 15, 2012 at 8:45 PM, Jeff Winkler <wink...@gmail.com> wrote:
Hi-
 I'm scripting some checks to verify page contents with and without MPS. Using the modpagespeed.com examples to learn and practice on. For some reason, defer_javascript is unchanged when fetched programatically -- despite having the X-Mod-Pagespeed header!

 An simpler repro case in Groovy.. this fails:


Any ideas? This is really strange.
Thanks,
Jeff Winkler

----------

groovy> assert html.contains ('pagespeed.deferInit()') 
 
Exception thrown
Oct 15, 2012 8:44:07 PM org.codehaus.groovy.runtime.StackTraceUtils sanitize

WARNING: Sanitizing stacktrace:

Assertion failed: 

assert html.contains ('pagespeed.deferInit()')
       |    |
       |    false
       <html>
         <head>
           <title>defer_javascript example</title>
         </head>
         <body>
           <!-- All Script tags will be deferred until page onload is triggered -->
           <p>
           If defer_javascript is enabled, '*'s and images will appear before script
           text. If not the script text will be interspersed with '*'s and images.
           </p>
           <script>
             function sleep(ms) {
               var sleep_now = Number(new Date());
               while(sleep_now+ms>Number(new Date())) { var tmp = sleep_now; }
             }
             sleep(2000);
             var state = 0;
           </script>
           <p>
             <script src="rewrite_javascript.js" type="text/javascript" id="ext1">
             </script>
           </p>
           <p>*</p>
           <img src="images/Puzzle.jpg"><br/>
           <p>*</p>
           <script>
             sleep(2000);
             document.write('<p>Inline Script 1</p>');
           </script>
           <p>*</p>
           <img src="images/BikeCrashIcn.png"><br/>
           <p>*</p>
           <script>
             sleep(2000);
             document.write('<p>Inline Script 2</p>');
           </script>
           <p>*</p>
           <img src="images/Cuppa.png"><br/>
           <p>*</p>
         </body>
       </html>

Kishore Simbili

unread,
Oct 15, 2012, 9:29:03 PM10/15/12
to mod-pagesp...@googlegroups.com
Hi,

defer_javascript works only with certain user_agents. Are you using any userAgent for your requests?
It is supported only with modern browser userAgents like , chrome, firefox, safari and IE9 and above.
Try using any of those , and I think it should work.

Thanks,
Kishore
Reply all
Reply to author
Forward
0 new messages