SatelliteWP / rocket-nginx

Rocket-Nginx is a Nginx configuration that makes WP-Rocket even faster by serving static pages directly without loading WordPress or PHP.
MIT License
579 stars 129 forks source link

Cache-Control values could support bfcache usage? #197

Closed E-VANCE closed 11 months ago

E-VANCE commented 11 months ago

This isn't a bug – more of a feature request / question regarding the current Cache-Control-implementation...

Having read up on the browser bfcache this morning and testing our site with Chrome's Dev Tools, I found it isn't comaptible due to no-cache, no-store, must-revalidate.

By default WP Rocket seems to be using max-age=0 and that allows for the bfcache to be applied.

I have adjusted the template file accordingly but was wondering if you see any major downsides when it comes to tweaking the Cache-Control-header in this fashion?

Or maybe the max-age=0 could become the default and all sites would benefit from a bfcache...?

Thanks a lot for providing this config, very helpful! 🙏

maximejobin commented 11 months ago

I have adjusted the template file accordingly

Is there a reason for changing the template instead of editing the configuration file?

You can change the Cache-Control and add headers by simply editing the configuration. No need to edit the template.

That being said, I will take a look and see if/how the project can be improved!

maximejobin commented 11 months ago

After reading on BF Cache and the needed modifications, I'm happy to say that Rocket-Nginx is already compatible with BF Caching!

All you have to do is to change the line in your rocket-nginx.ini configuration from:

html_cache_control = "no-cache, no-store, must-revalidate"

To:

html_cache_control = "no-cache, must-revalidate"

Then, run the rocket-parser.php file again, reload the Nginx configuration, and you're done!

For security reasons, I will not change the default configuration to make it compatible with BF Cache. It will be up to the server administrator to validate if the website can have its data in cache.

I tested it on my personal website and it works as shown from the Dev Console > Application tab under the Back/forward cache section (under Background services).

image