How To Clear WeChat Cache

Question

In order to improve its performance, WeChat has cached WeChat web pages, and ordinary methods cannot be cleared in time. After the project is updated, WeChat cannot update the content of the webpage in time.

solution

Change the server configuration to force entry files not to be cached, usually the homepage of the website (index.html), other static caches are normal, and then for the resource files (js/css) introduced in the homepage, modify the file name and file introduction link to force a new one Avoid caching of files.

Steps

  1. Modify the configuration file (nginx.conf) in nginx, and add #### kill cache under the location / matching the homepage of all websites, as follows:
location / {
    root /mnt/dat1/test/tes-app;
    index index.html index.htm;
    try_files $uri $uri/ /index.html;
    #### kill cache
    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;
}
  1. Modify the resource import link in index.html, there are two situations:
  • First, the front-end framework has already prepared the packaged file name to automatically carry the hash value, and the import link is also automatically modified. In this case, there is no need to manually modify the file name
  • The second is the original import method used by some systems. If there is no automatic packaging system, you need to manually change the file name and import link by yourself, as follows:
<script type="text/javascript" src="js/login.js" ></script>

change to

<script type="text/javascript" src="js/login_01.js" ></script>

And rename login.js to login_01.js

Comments