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
578 stars 129 forks source link

Starting at 3.16, mobile cache is activated by default #214

Open maximejobin opened 1 month ago

maximejobin commented 1 month ago

Starting at 3.16, mobile cache is activated by default on new installations following the removal of the Cache tab.

This means two cache files are generated (desktop and mobile) and we need to be able to know if the visitor comes from mobile or not.

This could be tricky as identifying the device is not easy with Ngnix's scripting language.

Could be based on the JSON from Mobile Detect.

ctekk7 commented 2 weeks ago

hello, with wp rocket pushing "mobile cache" with all the benefits of "Optimize critical images" and "reduce unused css" (which benefits both desktop and mobile total file size) I wonder what the current best caching option is for powerful dedicated hosting?

Have you already decided whether you will improve rocket-nginx (if even possible) to support mobile cache from wp rocket?

sriharsha-y commented 1 week ago

I have Cloudflare in front of Nginx which actually sends me CF-Device-Type header which can have either mobile, tablet (or) desktop as a value. Will this be useful in identifying and serving mobile specific cache by Nginx ?

I see WpRocket already has compatibility with CloudFlare APO which I am currently using and have enabled device specific cache there also (as it is recommended by WPRocket)

Cloudflare uses regex defined here https://developers.cloudflare.com/automatic-platform-optimization/reference/cache-device-type Since WPRocket is compatible with Cloudflare can we use such regex ?

ctekk7 commented 1 week ago

we also use cloudflare (pro) together with wprocket

sriharsha-y commented 1 week ago

I have made a direct fix in my config file and it seems to pick proper mobile caches with help of CloudFlare CF-Device-Type Header (Need to enable Cache By Device Type in APO) Leaving it here if someone needs until we have a solution https://gist.github.com/sriharsha-y/4182b601c2daef407758d90cb3e68fe4

Added below checks & commented out existing mobile cache checks https://gist.github.com/sriharsha-y/4182b601c2daef407758d90cb3e68fe4#file-rocket-nginx-tmpl-L99 https://gist.github.com/sriharsha-y/4182b601c2daef407758d90cb3e68fe4#file-rocket-nginx-tmpl-L166

ctekk7 commented 1 week ago

awesome thank you

maximejobin commented 1 week ago

Based on Cloudflare documentation, these rules that are incomplete and not perfect could be implemented: https://developers.cloudflare.com/automatic-platform-optimization/reference/cache-device-type/

I do not have enough data to know if it covers 99.9% of all requests or if it 85%.

Implementing Mobile Detection perfectly would be nearly impossible using Nginx's scripting language.