nginx caches JS for one hour. How to update the cache?
天蓬老师
天蓬老师 2017-05-16 17:24:48
0
8
766

nginx caches JS for one hour, as follows

location ~ .*\.(js|css)?$ { expires 1h; }

OK, this is no problem. I want to refresh the cache temporarily. At worst, I can just add a suffix, for example:abc.js?v=123

Now that I have debugged online, I want to remove the suffix and restoreabc.js?v=123toabc.js, but it is still cached at this time. , how to break it?

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all (8)
習慣沉默

Your rule above just adds an expiration rule to the header
Tell the browser that this thing expires in 1 hour
It’s not that nginx caches it

    黄舟

    This cache refers to the cache of your browser (client, not nginx). Under normal circumstances,Ctrl+Rforced refresh will remove the cache.
    Or clear your browser cache and it will be OK.

      过去多啦不再A梦
      1. Keep suffix
      2. Change file name
        漂亮男人

        Don’t use a purge cleaning module?

          仅有的幸福

          grunt-rev

          Use the rev task together with yeoman/grunt-usemin for cache busting of static files in your app. This allows them to be cached forever by the browser.

          This way, nginx header settings will never expire.

            刘奇

            Using fis, the best front-end solution in the Eastern Hemisphere, we have a dedicated set of solutions.
            fis

              仅有的幸福

              http://labs.frickle.com/nginx_ngx_cache_purge/README

              http { proxy_cache_path /tmp/cache keys_zone=tmpcache:10m; server { location / { proxy_pass http://127.0.0.1:8000; proxy_cache tmpcache; proxy_cache_key $uri$is_args$args; } location ~ /purge(/.*) { allow 127.0.0.1; deny all; proxy_cache_purge tmpcache $is_args$args; } } }

              Visit 127.0.0.1/purge/abc.js to delete cached files.
              Add the parameter --add-module=/path/to/ngx_cache_purge when configuring to add this third-party purge module.

                过去多啦不再A梦

                Similar toexpiresmax-agee-tagThese header information are cache headers for front-end browsers. For example, if you just set expires for one hour, then the browser will not request the file again one hour after the request is completed. To communicate with the server, local cache files are used every time. Within this hour, only the browser clears the cache or disables the cache in the developer tools to communicate with the server. Otherwise, any changes to the file on the server within this hour will have no impact on the browser. .

                  Latest Downloads
                  More>
                  Web Effects
                  Website Source Code
                  Website Materials
                  Front End Template
                  About us Disclaimer Sitemap
                  php.cn:Public welfare online PHP training,Help PHP learners grow quickly!