You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all, this is a good project. It solves the compatibility problem of different browsers, but I think we can add a method to disable caching
I have a problem here. In the following example, when I modify the content on the left for the second time, I click the render button and find that the iframe on the right is not re rendered because the fetch request is cached
At this point, unless I call the reload method to clear the cache
But I can't do that
This will cause the CDN link to send the request again and the waiting time is too long
So I'd like to add a method to let users freely decide whether to use fetch cache
code
<!DOCTYPE html><htmllang="en"><head><metacharset="UTF-8"><metahttp-equiv="X-UA-Compatible" content="IE=edge"><metaname="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>
.box {
width:48vw;
height:300px;
resize: none;
}
</style></head><body><textareaclass="box" spellcheck="false">
export default function() {
return 'Current Time: ' + Date.now()
}
</textarea><iframeclass="box"></iframe><divstyle="text-align: center;"><buttonid="render">Render</button></div><script>constbtn=document.querySelector('#render')consttextarea=document.querySelector('textarea')constiframe=document.querySelector('iframe')btn.addEventListener('click',()=>{consttemplate=genTemplate(textarea.value)iframe.contentDocument.open()iframe.contentDocument.write(template)iframe.contentDocument.close()})functiongenTemplate(text){return` <div id="app"></div> <script> var originPath = window.location.origin + window.location.pathname var publicPath = originPath.slice(0, originPath.lastIndexOf('/') + 1) var VirtualFiles = ${JSON.stringify({'app.js': text})} var files = {} for (const filename in VirtualFiles) { files[publicPath + filename] = VirtualFiles[filename] } window.esmsInitOptions = { shimMode: true, fetch: async (url, options) => { const content = files[url] if (content) return new Response(new Blob([content], { type: 'application/javascript' })) return fetch(url, options) }, // // This method can be used to selectively disable caching // disableCache: (url, options, source) => { // if (files[url]) return true // } } <\/script> <script async src="https://cdn.jsdelivr.net/npm/[email protected]/dist/es-module-shims.min.js"><\/script> <script type="module-shim"> import RenderFn from './app.js' const dom = document.querySelector('#app') setInterval(() => dom.innerHTML = RenderFn(), 1000 / 60) <\/script> `}</script></body></html>
The text was updated successfully, but these errors were encountered:
In general, one of the goals for ES Module Shims is to follow native browser specifications as closely as possible.
Not caching modules is unfortunately quite a big shift away from the way that browsers work.
Rather a better way to achieve this kind of thing is to add a query parameter to the URL with a resolve hook. The hot reloader uses a similar technique in the PR at #269 coming in the next release.
First of all, this is a good project. It solves the compatibility problem of different browsers, but I think we can add a method to disable caching
I have a problem here. In the following example, when I modify the content on the left for the second time, I click the render button and find that the iframe on the right is not re rendered because the fetch request is cached
At this point, unless I call the reload method to clear the cache
But I can't do that
This will cause the CDN link to send the request again and the waiting time is too long
So I'd like to add a method to let users freely decide whether to use fetch cache
code
The text was updated successfully, but these errors were encountered: