Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to prevent CDN from caching mobile pages for PC

Shulou Source: shulou.com Published: 2022-06-01 10:26:05 09月17日 Update

In this issue, the editor will bring you about how to avoid CDN caching mobile pages on PC. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.

This problem does not occur if the PC side and the mobile side are the same set of code. "the problem is that PC and mobile are two sets of code, but share the same domain name. "

The configuration of using nginx is as follows: judge whether the mobile end is mobile according to UA, and follow different logic (to determine whether the mobile end of UA is prone to problems)

Location / {

/ / default PC side

Root / usr/local/website/web

# judge the UA and access the mobile terminal

If ($http_user_agent ~ * "(Android | webOS | iPhone | iPad | BlackBerry)") {

Root / usr/local/website/mobile

}

Index index.html index.htm

}

Solutions typically use Vary response headers to control how CDN caches different request headers.

"Vary: User-Agent can be used here, which means that if the User-Agent is different, the request is re-initiated instead of reading the page from the cache"

Vary: User-Agent

Of course, there are too many User-Agent, and there will be too much cache invalidation at this time.

A brief answer

Using Vary: User-Agent, caching is based on UA.

Vary: User-Agent

However, it is best not to do so. If there are two sets of codes for PC and mobile, two domain names are recommended for the following reasons

Nginx determines whether the mobile side is error-prone and unfriendly to cache. this is how to prevent CDN from caching mobile pages on PC. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Tags: Mobile caching pages code problems differences content domain names too many analysis professional two small and medium representative rich in content that is suggestions situations articles solutions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information OPPO Reno Linux MySQL Docker