Preventing browser caching on web application upgrades

跟風遠走 提交于 2019-12-04 08:42:32

Append somethign to the URL as parameter, e.g. myresource.css?version=1. The file will be servered correctly, that's a trick to force reloading the cache. You only need to generate the html page dynamically.

I've heard talk of using version numbers in the filenames you want you users caching, but I can't speak to how "good" that is compared to other options.

Options I can think of:

  • Reduce the cache TTL
  • Store the cacheable stuff in a versioned directory tree, e.g.:
    • /app/1.2/css/
    • /app/1.2/js/

You can use below format for auto random versioning

for js file:

<script type="text/javascript" src="js/app.js?seq=<%=DateTime.Now.Ticks%>"></script>

and for css file:

<link rel="stylesheet" type="text/css" href="Styles/styles.css?seq=<%=DateTime.Now.Ticks%>" />

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!