【发布时间】:2021-05-24 06:47:29
【问题描述】:
我在 web 应用中有一个按钮,点击该按钮时应该hard-重新加载页面及其所有组件。
我对其中一个 javascript 文件 (file1.js) 进行了更改,但更改未更新。
根据:
here 和
here 使用 window.location.reload(true);
应该从服务器重新加载页面。
在我的程序中,单击按钮会触发这行代码,但更改仍然没有显示出来。
代码通过 webpack 打包。
点击按钮时,Chrome 调试器中的网络标签会显示与重新加载页面相关的网络请求。
其中之一是主页。
- 它的请求标头显示
cache-control: no-cache - 它的响应标头显示
Cache-Control
在列表的更下方,我看到 app.bundle.js,其中包括特定文件 file1.js。app.bundle.js 的 General 部分显示 Status Code: 200 (from memory cache)
很明显,并非页面的所有元素都是从服务器重新加载的。
以下是 Chrome 调试器“网络”选项卡中的部分。
如何强制加载所有页面,而不是从缓存中加载?
# Network request fields for getting https://staging.bldlog.com/index
General:
Request URL: https://staging.bldlog.com/index
Request Method: GET
Status Code: 200
...
Request Headers:
:authority: staging.bldlog.com
:method: GET
:path: /index
...
cache-control: no-cache
Response Headers:
access-control-allow-headers: DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range
# --------------------------------------------------------------
# Network request fields for getting https://staging.bldlog.com/V1/build/mlj/app.bundle.js
General:
Request URL: https://staging.bldlog.com/V1/build/mlj/app.bundle.js
Request Method: GET
Status Code: 200 (from memory cache)
【问题讨论】:
-
感谢您的评论。它帮助我找到了答案。
标签: javascript caching browser-cache cache-control