In the previous article "The HTTP caching mechanism you deserve to know (detailed code explanation)", we learned about the HTTP caching mechanism. The following article will help you understand the problem of entry caching in Vue. Let's take a look.
Regarding the caching strategy ofweb
, I recommend this article:Http Cache Mechanism
We often encounter a problem during development. We control caching issues based on the version number. When we release a new version and use the version number, we find that the version number quoted inhtml
is the old version number. , it turns out that the html file has been cached. Many times we set it to prohibit thehtml
file from being cached, but it still happens to be cached.
Why do we sometimes setThis kind of mandatory prohibition of caching, our page Still cached?
Because we only focused on the client, but ignored the server-side settings. If the server-side nginx setsCache-control
, it will overwrite the ## settings on our page. #Cache-control, so sometimes we will find that the version numbers of
cssand
jshave been added, but the old
is still referenced in the html file. cssand
jsfiles
jsand
css# will be deleted before each version is released. ## file, thenindex.html
will not be able to load the previousjs
,css
and some other static resource files, and the newjs
andcss
will not be loaded, and a white screen will appear.Due to the caching mechanism of the server, the old
and You can only set one The browser will Caching, but the server will be requested when refreshing the page or reopening it. The server can respond The above is the detailed content of A brief analysis of the problem of entry caching in Vue (code sharing). For more information, please follow other related articles on the PHP Chinese website!js
will not be deleted immediately. In this case, you need to cooperate with the server to set up the cache tonginx
For examplelocation / { root /home/www/test/dist; index index.html; try_files $uri $uri/ /index.html; add_header Last-Modified $date_gmt; add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0'; if_modified_since off; expires off; etag off; }
304
. If the file is changed, it will respond200
##no-store
Recommended learning:
vue.js tutorial