This article is collected on GitHub DailyQuestion: DailyQuestion, including big factory promotion opportunity, interview book and several interview questions, study 5 minutes a day, a year to enter the big factory.

  • Dachang Face Sutra
  • Big push

This problem does not occur if PC and mobile are the same code. “The problem is that PC and mobile are two sets of code that share a domain name.”

Use nginx configuration as follows, according to UA to determine whether mobile terminal, and follow different logic (determine whether mobile terminal is prone to problems)

Location / {// default PC root /usr/local/website/web; # UA, access to the mobile end if ($http_user_agent ~ * "(Android | webOS | the | the | BlackBerry)") {root/usr/local/website/mobile; } index index.html index.htm; }Copy the code

Solutions typically use the Vary response header to control the CDN’s caching of different request headers.

Here you can useVary: User-Agent, indicating that if the User-Agent is different, the request is re-initiated instead of reading the page from the cache

Vary: User-Agent
Copy the code

Of course, if there are too many user-agents, there will be too many cache invalidation.

Short answer

Vary: user-Agent is used to cache by UA.

Vary: User-Agent
Copy the code

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

  1. nginxDetermine whether the mobile terminal is prone to error
  2. Not cache friendly

More job interview

  • [Byte – Video Architecture Group – Front End] The headline architecture group invited a self-test
  • [Meituan] What are anti-shake and throttling, and what are their application scenarios
  • How to get the memory of a process and monitor it

Pay attention to my

This article is collected on GitHub DailyQuestion: DailyQuestion, including big factory promotion opportunity, interview book and several interview questions, study 5 minutes a day, a year to enter the big factory.

  • Dachang Face Sutra
  • Big push

My name is Shanyue and I am dedicated to “answering a big interview question every day with a short five-minute answer”. You can scan the code to follow, or reply to wechat in the public account to communicate with me.

Five minutes a day, six months in dachang

This article is formatted using MDNICE