I would like to turn on caching for my Trellis / Digital Ocean powered site and I am aiming to get the PageSpeed ‘Leverage browser caching’ point ticked off.
I did not set cache: true in production/wordpress_sites.yml when I provisioned / first launched the site.
I have since set cache: true and tried a deployment. I have also tried a deploy using the fastCGI settings.
–
Do I need to reprovision the server to activate the cache - or are both types of caching not recognised by PageSpeed?
But it does not seem to have activated the cache. Looking in server.yml I can’t see any stage for the cache so I feel like I’ve taken the wrong step for re-provision. The link below says the server playbook is the right command for re-provision, feeling confused !
I think I can see the confusion here. Page Speed’s Leverage browser caching warning is to do with caching of assets, not page caching. The FastCGI cache, as outlined in the Trellis docs here: https://roots.io/trellis/docs/fastcgi-caching, is in regards to page caching.
To solve the Page Speed warning, you’d want to add expiry headers to your assets. With Trellis, this can be done with an Nginx include. There may be a better way of doing this but it can be achieved by:
Add the following directory: trellis/nginx-includes/sitename.com. Sitename would obviously reflect your particular setup.
Within this directory, add a new file called cache.conf.j2
Then reprovision. You can also add a flag to your provision command to speed things up: ansible-playbook server.yml -e env=production --tags nginx-includes.
Thanks for the replies all, Will test on Monday - I’ve updated the thread title to help anyone wanting from the future wanting to get the ‘Leverage browser caching’ tick on PageSpeed
Did you try this…
Tip: Once you have set up your sites templates, append --tags nginx-sites to your command to run only the Nginx sites portions of the playbook. Reference