Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
maximejobin opened this issue May 22, 2024 · 11 comments
Closed

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

maximejobin opened this issue May 22, 2024 · 11 comments
Milestone

Comments

@maximejobin
Copy link
Collaborator

maximejobin commented May 22, 2024

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
Copy link

ctekk7 commented Jun 21, 2024

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
Copy link

sriharsha-y commented Jun 25, 2024

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
Copy link

ctekk7 commented Jun 25, 2024

we also use cloudflare (pro) together with wprocket

@sriharsha-y
Copy link

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
Copy link

ctekk7 commented Jun 25, 2024

awesome thank you

@maximejobin
Copy link
Collaborator Author

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.

@maximejobin maximejobin added this to the 3.1 milestone Jul 8, 2024
@maximejobin
Copy link
Collaborator Author

I just released version 3.1.0 beta where mobile detection is supported using Cloudflare's regex rules.

This is not perfect as Nginx's scripting does not allow all functions needed for full detection but it should cover the same devices as Cloudflare.

If you can test and let me know if it works well or not, it would be appreciated.

https://github.com/SatelliteWP/rocket-nginx/releases/tag/v3.1.0-beta

@ctekk7
Copy link

ctekk7 commented Jul 15, 2024

Awesome, thank you! I'll let you know as soon as we implemented it!

@ctekk7
Copy link

ctekk7 commented Jul 17, 2024

Desktop works well for us, thank you. What I coudn't test was mobile (as I don't have the right tools on my phone).

@JoAllg
Copy link

JoAllg commented Jul 23, 2024

@maximejobin thank you for this update!

Mobile detection works well. I have tested a few Android and iOS user agents (using desktop firefox Tools -> Web Developer- > Responsive Design View).

Of course it is not able to detect all mobile browsers. For example at the Android Section at https://deviceatlas.com/blog/mobile-browser-user-agent-strings you can see that there are some Android Browsers that will not be detected currently. The only identifiable string in their user agent would be their browser short name.

You probably don't want to go down the rabbit hole of detecting mobile browser variants and mobile devices.
What do you think about keeping on the safe side by :

  • Detect desktop browsers (Windows NT|Macintosh|X11) to serve desktop cache.
  • Do not serve cache if neither mobile or desktop is detected.

?

@maximejobin
Copy link
Collaborator Author

What do you think about keeping on the safe side by :

Detect desktop browsers (Windows NT|Macintosh|X11) to serve desktop cache.
Do not serve cache if neither mobile or desktop is detected.

The detection regex is in a configuration variable. Therefore, you can edit it if you want!

If I cannot detect that it is indeed a mobile, then it is a desktop. Not serving any file would not make sense to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants