[英]service worker caching issues on netlify/cloudfront/CDN
I use a service worker to cache my PWA. 我使用服务工作者来缓存我的PWA。 Everything is working fine on my VPS.
我的VPS一切正常。 Now, when i want to host on Netlify, caching breaks due to their CDN.
现在,当我想在Netlify上托管时,由于CDN导致缓存中断。
"./script.js" “ ./script.js”
becomes 变
" https://d33wubrfki0l68.cloudfront.net/js/5ae4b88dedf0edb18f2281d6c6b0339b122ad0/.../script.js " “ https://d33wubrfki0l68.cloudfront.net/js/5ae4b88dedf0edb18f2281d6c6b0339b122ad0/.../script.js ”
so that the file is not found in the sw-cache. 以便在sw-cache中找不到该文件。 Obviously, that breaks offline functionality.
显然,这会破坏离线功能。
Is there a solution for caching with CDNs? 有CDN缓存解决方案吗?
If you want to keep the asset optimization enabled, you can try loading your script.js with the data-dont-bundle
attribute, like: 如果要保持启用资产优化,则可以尝试使用
data-dont-bundle
属性加载script.js,例如:
<script data-dont-bundle src="/script.js"></script>
This attribute will tell netlify not to optimize that file. 此属性将告诉netlify不优化该文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.