问题
If the source code or function is changed in the SPA project, you must deploy it to the server again.
If the service is deployed, it will continue to load the cached js value unless refreshed. How do I fix this?
回答1:
Say all of your SPA code are two files: vendor.js
and app.js
. To miss the cache when updated, typically what is done is compute hashes of the contents and put it in the file name: vendor.<truncated md5 hash>.js
and app.<truncated md5 hash>.js
. Each time you build the project (assuming you changed at least one line) it gets a new hash, therefore a new filename, and miss the cache.
回答2:
If you have used webpack, in output entry just specify the filename like
output: {
filename: '[name].[contenthash].js',
path: '/'
}
This would fix the issue by creating new hash for output file whenever the content of file changed.
来源:https://stackoverflow.com/questions/61189377/how-to-refresh-in-spa-react-vue