How to refresh in SPA (react, vue)?

不羁的心 提交于 2020-05-31 07:07:49

问题


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

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