JS files not compressed after mod_pagespeed

929 views
Skip to first unread message

Ilari Mäkelä

unread,
Jan 25, 2014, 9:45:01 AM1/25/14
to mod-pagesp...@googlegroups.com
I've been setting up my system to use nginx with mod_pagespeed but I'm having troubles with .js files not being compressed while .css files are compressed correctly. I'm running nginx 1.4.4 and mod_pagespeed v1.7.30.3-beta. My pagespeed specific configuration is the following:
  pagespeed on;
  pagespeed EnableFilters combine_css,combine_javascript;
  pagespeed FileCachePath /var/ngx_pagespeed_cache;
  pagespeed RespectXForwardedProto on;
  pagespeed FileCacheSizeKb            102400;
  pagespeed FileCacheCleanIntervalMs   3600000;
  pagespeed FileCacheInodeLimit        500000;
  pagespeed LRUCacheKbPerProcess     8192;
  pagespeed LRUCacheByteLimit        16384;
  pagespeed LoadFromFile "https://www.example.com/static" "/var/www/example.com/static";

And then under server:
  #  Ensure requests for pagespeed optimized resources go to the pagespeed
  #  handler and no extraneous headers get set.
  location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" { add_header "" ""; }
  location ~ "^/ngx_pagespeed_static/" { }
  location ~ "^/ngx_pagespeed_beacon$" { }
  location /ngx_pagespeed_statistics { allow 127.0.0.1; deny all; }
  location /ngx_pagespeed_global_statistics { allow 127.0.0.1; deny all; }
  location /ngx_pagespeed_message { allow 127.0.0.1; deny all; }
  location /pagespeed_console { allow 127.0.0.1; deny all; }

I've been debugging but haven't found a reason why pagespeed is not compressing .js files. Any ideas?

Charles Weiblen

unread,
Jan 25, 2014, 9:47:50 PM1/25/14
to mod-pagesp...@googlegroups.com
I am having the same problem, but seeing issues with both css and js.  Been looking all day at every possible configuration setting that I might be missing, but had no success.

Joshua Marantz

unread,
Jan 27, 2014, 7:55:34 AM1/27/14
to mod-pagespeed-discuss
Are you talking about gzip compression?  Or are you talking about the minification performed by the pagespeed filters rewrite_javascript and rewrite_css?

-Josh



--
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/34ab0431-8bd4-4145-bb29-12fe2ba1394e%40googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

Shawn Ligocki

unread,
Jan 27, 2014, 11:13:59 AM1/27/14
to mod-pagesp...@googlegroups.com
Assuming that you are saying that your resources are not getting rewritten by mod_pagespeed, see: https://developers.google.com/speed/pagespeed/module/faq#not-rewriting

Specifically:

There are several reasons that could happen:
  • The filters you have enabled aren't aggressive enough.
  • Your resources (images, css, javascript) aren't cacheable. If PageSpeed sees cache-control headers such as nocache or private it will not rewrite the resources.
  • CSS, JavaScript, and image files served from a distinct domain from the HTML must have the resource domain authorized. See Domains.
  • Your CSS has new CSS3 syntax or other constructions we don't support. See issue 108. The fallback_rewrite_css_urls filter may be able to help. You can also use the standalone CSS parser to help debug these issues.
  • Your resources are served over HTTPS. HTTPS resources can currently only be rewritten if they are origin-mapped or loaded from directly from the file-system. See HTTPS Support.
If you send a link to your site we could probably help you figure out the problem.



Charles Weiblen

unread,
Jan 27, 2014, 11:41:13 AM1/27/14
to mod-pagesp...@googlegroups.com
Thanks, Shawn, I am pretty sure I have all of the bases covered mentioned by the FAQ.


I appreciate the help!

Shawn Ligocki

unread,
Jan 27, 2014, 12:56:34 PM1/27/14
to mod-pagesp...@googlegroups.com
Hi Charles, looking at your source code, you have included CSS and JS files in a way that does not work well for mod_pagespeed:


<style>@import url(vendor/h5bp/css/normalize.css) ;@import url(vendor/h5bp/css/main.css) ;@import url(vendor/bootstrap/css/bootstrap.css) ;@import url(vendor/bootstrap/css/bootstrap-datepicker.css) ;@import url(vendor/bootstrap-formhelpers/bootstrap-formhelpers.css) ;@import url(vendor/backgrid/backgrid.css) ;@import url(vendor/backgrid/backgrid-filter.css) ;@import url(vendor/backgrid/backgrid-paginator.css) ;@import url(app/styles/base.css) ;@import url(app/styles/login.css) ;@import url(app/styles/sticky-footer.css) ;</style>
...
<script data-main="/app/config" src="/vendor/js/libs/require.js"></script>

This CSS style is very strange, usually CSS is used like this:

<link rel="stylesheet" href="vendor/h5bp/css/normalize.css">
<link rel="stylesheet" href="vendor/h5bp/css/main.css">
...

We do have a filter (flatten_css_imports) that ought to help here, but it may have exceeded the maximum number of bytes or something like that. In general it will help if you can use the standard <link> syntax rather than @imports.

Similarly, it looks like you are only referencing 1 JS file in your HTML: require.js. I'm not sure why we aren't minifying that one, but we have no way to rewrite any of the others because they are loaded from inside that JS file.

I'm guessing this code was produced by your CMS so you can't change it though?

If so, you can turn on InPlaceResourceOptimization (the doc says it's not available for Nginx, but it is now ... I'll update the doc):

pagespeed InPlaceResourceOptimization on;

this will minify CSS and JS even if the HTML parser can't find them (like it can't seem to find yours).


--
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.
Reply all
Reply to author
Forward
0 new messages