简体   繁体   English

webpack代码拆分:它是否提供浏览器缓存

[英]webpack code splitting: does it provide browser caching

When we use lazy-loading for downloading specific web modules, eg: 当我们使用延迟加载来下载特定的Web模块时,例如:

import('./polyfills').then(render);

Will the browser cache these dynamically loaded files and does webpack use the cached version on subsequent requests? 浏览器是否会缓存这些动态加载的文件,webpack是否会在后续请求中使用缓存版本?

With bundle splitting I know the browser will cache the loaded files; 使用bundle拆分我知道浏览器将缓存加载的文件; I assume this should be the same for code splitting, but I'm not sure. 我认为这对于代码拆分应该是相同的,但我不确定。

Cache-Control response header specifies if and for how long a resource can be cached. Cache-Control响应头指定可以缓存资源的时间和长度。 Your server is responsible for setting it. 您的服务器负责设置它。

When webpack-generated code encounters a dynamic import, it fetches and then executes it. 当webpack生成的代码遇到动态导入时,它会获取然后执行它。 Whatever is exposed by the module is then available as long as the page isn't closed/reloaded and when the same import is encountered again those in-memory bindings are used (the module isn't refetched or executed again). 只要页面未关闭/重新加载,并且再次遇到相同的导入时,就会使用模块公开的内容(使用内存中的绑定)(不会重新获取或重新执行模块)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM