3

Magento is running on 1.9.x, and web server is Nginx having Varnish installed on it using Turpentine plugin. Site speed is very fine when running from any browser due to Varnish cache but page speed showing in Google PageSpeed Insights, GTmetrix or Pingdom all are specifically suggesting to "Leverage browser caching". I made the changes in /etc/nginx/conf.d/default.conf & /etc/nginx/conf.d/mysite.conf and restarted all services

location ~*  \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 365d;
log_not_found off;
}

But still getting the exact same result on page speed sites, so since I am running Varnish on port 80 I googled around and changed settings in /etc/varnish/default.vcl & in /var/www/vhosts/example.com/httpdocs/var/default.vcl to include and restarted all services

sub vcl_backend_response {
    if (bereq.url ~ "\.(png|gif|jpg|swf|css|js)$") {
    unset beresp.http.set-cookie;
    set beresp.http.cache-control = "max-age = 2592000";
  }
}

But intrestingly there is no change in page speed sites and all of them are still explicitly sugesting heavily to 'Leverage browser caching'. I even tried with different network connection/location thinking that there may be some issues with these websites but still the same result.

http://www.example.com/media/wysiwyg/images/image.PNG (expiration not specified) http://www.example.com/media/wysiwyg/images/image2.PNG (expiration not specified) http://www.example.com/widgets.js (30 minutes) http://www.example.com/analytics.js (2 hours) http://www.example.com/media/wysiwyg/images/image7.jpg (8 hours)

can someone please shed light on this and help me to resolve this issue? also Turpentine plugin is being used for having Varnish with Magento, do we need to look into that maybe?

  • have you enabled static cache in varnish admin settings? it will be enough with nginx expires headers. – MagenX Mar 20 '16 at 9:01
  • @MagenX these settings are bedefualt enabled, not still no luck Admin->Configuration->TURPENTINE->Caching Options->Static Caching->Force Static Asset Caching = Enable Admin->Configuration->TURPENTINE->Caching Options->Static Caching->Static Asset Extensions = css,js,jpe?g,png,gif,ico,swf Admin->Configuration->TURPENTINE->Caching Options->Static Caching->Use Simple Hash = Enable – Farmi Mar 20 '16 at 18:49
  • Have you verified that your changes to vcl_backend_response are indeed causing the cache-control header to be returned properly? – Aric Watson Mar 21 '16 at 16:59
  • @AricWatson I think I may be doing vcl_backend_response at wrong place? can you tell me exactly where do I need to do this? should it be custom VCL file which I need to create in location where TURPENTINE is showing it in admin options? and than add this code at the very last lines of that file? or will TURPENTINE will generate the custom file itself? – Farmi Mar 26 '16 at 8:04
  • I'd try this - generate a VCL from turpentine and apply it. Make sure everything's working. Then download that VCL and add your vcl_backend_response code to that file. Upload it to your server and apply it to the running Varnish configuration manually (not via Turpentine). Then clear caches and test a bit to see if the max-age = 2592000 header is being sent correctly and accomplishing what you want. If so, then we can figure out how to put into the custom_include VCL in Turpentine so it's included with Turpentine's generated VCL. – Aric Watson Mar 28 '16 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.