Can i load .js files from browser caché using xhr?

Hello everyone!

I been reading this article https://www.netlify.com/blog/2017/02/23/better-living-through-caching/ about caché.

I read there the fact that netlify uses etag to tell browsers; “there is no changes, you can load this resource from caché.”

My question is, can i implement sort of thing in javascript using XMLHttpRequest sending the etag? Maybe is factible save the etag in localStorage to caché the files?

I heavily use XHR in my web design https://fastframework.stringmanolo.ga/dev/#projects if you click any file, it’s loaded using xhr.

Is this right to do? Do i have to set other headers too or this just dosn’t work at all using XHR?
If not, what headers should i change using .toml file?

If it’s cache that you’re concerned about, why not use service workers? It’ll cache the files that you tell it to cache and then, any request (including XHR) made to the file will be served by service worker (if configured so).

Nice, i just did that! :smiley:

Way better solution since works everywhere.

1 Like