How can I force clients to refresh JavaScript files?

后端 未结 26 2281
旧时难觅i
旧时难觅i 2020-11-22 03:40

We are currently working in a private beta and so are still in the process of making fairly rapid changes, although obviously as usage is starting to ramp up, we will be slo

26条回答
  •  旧时难觅i
    2020-11-22 04:09

    Appending the current time to the URL is indeed a common solution. However, you can also manage this at the web server level, if you want to. The server can be configured to send different HTTP headers for javascript files.

    For example, to force the file to be cached for no longer than 1 day, you would send:

    Cache-Control: max-age=86400, must-revalidate
    

    For beta, if you want to force the user to always get the latest, you would use:

    Cache-Control: no-cache, must-revalidate
    

提交回复
热议问题