美文网首页
解决index.html缓存问题

解决index.html缓存问题

作者: web5 | 来源:发表于2020-04-07 14:24 被阅读0次

    解决index.html缓存问题

    一般项目发版后前端静态文件会有缓存问题,

    不强制刷新很难解决,

    但是用户不会去强制刷新,

    这就需要我们开发人员在配置方面解决浏览器缓存静态文件问题。

    一般浏览器缓存的文件有html、css、js等。

    css、js文件被缓存的解决方案

    一般html中引入的css和js的名字都加了哈希值,所以新版本css、js和就旧版本的名字是不同的,不会有缓存问题。

    如果index.html文件被缓存就稍微麻烦些

    首先可以在index.html文件头部添加mate标签禁止缓存

    <meta http-equiv="Expires" content="0">

    <meta http-equiv="Pragma" content="no-cache">

    <meta http-equiv="Cache-control" content="no-cache">

    <meta http-equiv="Cache" content="no-cache">

    浏览器的缓存解决,

    但是一般在服务器端还是会有缓存,

    当浏览器访问index.html时拿到的就是服务器缓存的文件,所有我们还需要解决服务器的缓存

    这需要在服务器配置不让缓存index.html

    nginx 配置如下:

    location = /index.html {

    add_header Cache-Control "no-cache, no-store";

    }

    相关文章

      网友评论

          本文标题:解决index.html缓存问题

          本文链接:https://www.haomeiwen.com/subject/lpfnphtx.html