gpt4 book ai didi

javascript - 服务器正在缓存 JS 文件或嵌入 HTML 脚本吗?

转载 作者:行者123 更新时间:2023-11-27 23:55:33 25 4
gpt4 key购买 nike

我的一个网站的服务器出现异常,我需要您的帮助来找到解决方案。

如果我打开 FtpZilla 下载的 PHP 文件并编辑任何 PHP 代码,一旦保存并重新上传该文件,新内容就会处于事件状态。对于任何 HTML 代码都是一样的

如果在同一个文件中我编辑一些 HTML 代码,其中有 <script></script>标签和里面的javascript代码,当我上传新版本的文件时,JS代码提供给浏览器的是旧的。我尝试使用 CTRL+F5,几个浏览器:没有出路。同样令人失望的结果,自“时间开始”以来清理每个浏览器的缓存

重新打开刚刚新上传的文件,令人惊讶的是我发现了我的新代码。就像服务器正在提供旧文件一样。但为什么只有 JS 部分?

不仅:对于任何 JS 外部文件,我都遇到同样的问题。我的意思是这些文件嵌入了标签 <script src=""></script>进入 HTML 页面

我尝试停用 .htaccess 中的任何缓存命令,如下所示。但在这种情况下也没有发生更好的事情。

请问我还能做什么?

# Requires mod_expires to be enabled.
<IfModule mod_expires.c>
# Enable expirations.
ExpiresActive On

# Cache all files for 2 weeks after access (A).
#ExpiresDefault A1209600

<FilesMatch \.php$>
# Do not allow PHP scripts to be cached unless they explicitly send cache
# headers themselves. Otherwise all scripts would have to overwrite the
# headers set by mod_expires if they want another caching behavior. This may
# fail if an error occurs early in the bootstrap process, and it may cause
# problems if a non-Drupal PHP file is installed in a subdirectory.
ExpiresActive Off
</FilesMatch>

#ExpiresByType image/jpg "access 1 year"
#ExpiresByType image/jpeg "access 1 year"
#ExpiresByType image/gif "access 1 year"
#ExpiresByType image/png "access 1 year"
#ExpiresByType text/css "access 1 month"
#ExpiresByType application/pdf "access 1 month"
#ExpiresByType text/x-javascript "access 1 month"
#ExpiresByType application/x-shockwave-flash "access 1 month"
#ExpiresByType image/x-icon "access 1 year"
#ExpiresDefault "access 2 days"
</IfModule>

编辑:我刚刚注意到:如果我创建到原始 JS 文件的符号链接(symbolic link),当我通过符号链接(symbolic link)读取文件时(因此在浏览器中我调用 SymLink 而不是文件):我仍然得到旧版本。甚至可以通过 FileZilla 打开(编辑)它。就像指针永久指向旧版本一样。如果我直接读取 JS 文件(直接调用它,甚至不通过嵌入链接)我可以获得新版本我越来越迷失了。

最佳答案

ExpiresActive Off 实际上将使您的浏览器能够缓存内容,因为服务器没有设置缓存规则。如果你想禁用缓存你可以使用这样的东西:

<FilesMatch "\.(html)$">
Header set Cache-Control "private, no-cache, must-revalidate"
Header set Pragma "no-cache"
</FilesMatch>

这将告诉您的浏览器检查每个请求的新内容。如果内容不是动态创建的(例如,通过 php)并且文件自您上次收到以来没有被修改,apache 将发送一个没有数据的 304 Not Modified header (因为您的浏览器已经拥有最新版本)

关于javascript - 服务器正在缓存 JS 文件或嵌入 HTML 脚本吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32297878/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com