pagespeed_static js_defer issues

416 views
Skip to first unread message

Antonio Laguna

unread,
Apr 6, 2015, 4:55:35 AM4/6/15
to mod-pagesp...@googlegroups.com
Hi here,

I've been watching some other topics about this subject but I can't see solutions applying to me. I've just activated the pagespeed module and I'm getting a non-cached version of pagespeed_static/js_defer. 

I've attached a screenshot showing the wrong ETag


This is the current configuration:

# sets the proxy cache path location, max size 2g
proxy_cache_path  /etc/nginx/cache  levels=1:2 keys_zone=STATIC:100m inactive=24h max_size=2g;

# transfers the `Host` header to the backend
proxy_set_header        Host $host;

# uses the defined STATIC cache zone
proxy_cache             STATIC;

# cache 200 10 minutes, 404 1 minute, others status codes not cached
proxy_cache_valid 200 10m;
proxy_cache_valid 404 1m;

proxy_cache_key "$scheme$host$request_uri";
proxy_cache_use_stale   error timeout invalid_header updating http_500 http_502 http_503 http_504;
proxy_http_version 1.1;

# transfers real client IP to your ghost app,
# otherwise you would see your server ip
proxy_set_header        X-Real-IP        $remote_addr;
proxy_set_header        X-Forwarded-For  $proxy_add_x_forwarded_for;

client_max_body_size  20m;
client_body_buffer_size    128k;

# default expires (browser cache) set to 1 minute
expires 1m;

# gzip every proxied responses
gzip_proxied any;

# gzip only if user asks it
gzip_vary on;

# gzip only theses mime types
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/json application/javascript;
gzip_static on;

# add a cache HIT/MISS header
add_header X-Cache $upstream_cache_status;

# do not show incoming Etags, if-modified-since is sufficient
proxy_hide_header Etag;

server {
  listen 80 default_server;
  listen [::]:80 default_server ipv6only=on;

  server_name www.funcion13.com; # Replace with your domain

  root /usr/share/nginx/html;
  index index.html index.htm;

  client_max_body_size 10G;

  pagespeed on;
  pagespeed RewriteLevel CoreFilters;
  pagespeed EnableFilters move_css_above_scripts,defer_javascript,lazyload_images;
  pagespeed EnableFilters prioritize_critical_css;
  pagespeed UseExperimentalJsMinifier on;
  pagespeed EnableFilters inline_google_font_css;
  pagespeed EnableFilters insert_dns_prefetch;

  location / {
    proxy_cache STATIC;
    proxy_cache_valid 200 30m;
    proxy_cache_valid 404 1m;
    proxy_pass http://ghost;
    proxy_ignore_headers X-Accel-Expires Expires Cache-Control;
    proxy_ignore_headers Set-Cookie;
    proxy_hide_header Set-Cookie;
    proxy_hide_header X-powered-by;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    rewrite "\d{4}\/\d{2}\/\d{2}\/([^.]+)(.*)$" /$1$2 permanent;
    rewrite ^(/wp-content/)(.*)$ /old/$2 permanent;
    expires 10m;
  }

  location /content/images {
    alias /var/www/ghost/content/images;
    access_log off;
    expires max;
  }
  location /old {
    alias /var/www/ghost/content/old;
    access_log off;
    expires max;
  }
  location /assets {
    alias /var/www/ghost/content/themes/lechuck/assets;
    access_log off;
    expires max;
  }
  location /public {
    alias /var/www/ghost/core/built/public;
    access_log off;
    expires max;
  }
  location /ghost/scripts {
    alias /var/www/ghost/core/built/scripts;
    access_log off;
    expires max;
  }
  location ~ ^/(?:ghost|signout) {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $http_host;
    proxy_pass http://ghost;
    add_header Cache-Control "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0";
  }
}

upstream ghost {
  server localhost:2368;
  keepalive 64;
}

Any ideas?
Screen Shot 2015-04-06 at 10.54.56.png

Jeff Kaufman

unread,
Apr 6, 2015, 8:34:41 AM4/6/15
to mod-pagespeed-discuss
I think you're missing some of the location directives from
https://developers.google.com/speed/pagespeed/module/configuration#module
:

# 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 ~ "^/pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }
> --
> 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/6cd19022-464e-4fcf-9967-161aeda7abed%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Antonio Laguna

unread,
Apr 6, 2015, 10:13:21 AM4/6/15
to mod-pagesp...@googlegroups.com
Seems I missed that!

I've added it and for now it had no effect. Added it on top of the first location if that matters. I

Jeff Kaufman

unread,
Apr 6, 2015, 10:37:08 AM4/6/15
to mod-pagespeed-discuss
Could you paste your updated config?
> --
> 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/63a1c0e1-75fa-47d8-800d-b9937305f56f%40googlegroups.com.

Antonio Laguna

unread,
Apr 6, 2015, 1:45:15 PM4/6/15
to mod-pagesp...@googlegroups.com
Sure!

  # Needs to exist and be writable by nginx.  Use tmpfs for best performance.
  pagespeed FileCachePath /var/ngx_pagespeed_cache;

  # 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 ~ "^/pagespeed_static/" { }
  location ~ "^/ngx_pagespeed_beacon$" { }

Jeff Kaufman

unread,
Apr 6, 2015, 2:28:25 PM4/6/15
to mod-pagespeed-discuss
Looking more at your config I see you have:

# default expires (browser cache) set to 1 minute
expires 1m;

Which explains the change I see, where js_defer now has see
"Cache-Control: max-age=60" instead of "Cache-Control: max-age=600".

(The 600s limit isn't applying anymore because its in "location /
{...}" and nginx only applies the most specific location block.)

Does it work for you to change:

location ~ "^/pagespeed_static/" { }

to:

location ~ "^/pagespeed_static/" { add header "" ""; }

?

If not, what about:

location ~ "^/pagespeed_static/" { expires off; }

?
>> > email to mod-pagespeed-di...@googlegroups.com.
> --
> 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/e0c94fba-690c-42eb-9ad3-233c8973d9cb%40googlegroups.com.

Antonio Laguna

unread,
Apr 6, 2015, 4:22:55 PM4/6/15
to mod-pagesp...@googlegroups.com
Hi Jeff, 

Thanks for your help. It seems that last idea did the trick: expires off sends the correct caching headers!

Thanks a million and good eye!
>> > To view this discussion on the web visit
>> >
>> > https://groups.google.com/d/msgid/mod-pagespeed-discuss/63a1c0e1-75fa-47d8-800d-b9937305f56f%40googlegroups.com.
>> >
>> > For more options, visit https://groups.google.com/d/optout.
>
> --
> 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
Reply all
Reply to author
Forward
0 new messages