4

I'm loading my site's Offline page in a service worker, and caching it for later.

The Offline page contains references to fonts and images via urls in the embedded CSS and HTML

Are there DOM functions within modern JS that let me extract all of these URLs, so that I can get the service worker to go and fetch (and cache) these too?

Please don't suggest regex/other manual response body parsing techniques.

halfer
  • 19,824
  • 17
  • 99
  • 186
Andrew Bullock
  • 36,616
  • 34
  • 155
  • 231
  • Are you sure you're solving the right problem? Browsers have offline mode these days. – Jonathan Wilson Dec 05 '18 at 09:01
  • For starters, you can get all stylesheet urls with this expression: `Array.prototype.slice.call(document.querySelectorAll('link')).filter(l => l.rel == 'stylesheet').map(l => l.href)` – Jonathan Wilson Dec 05 '18 at 09:04
  • "Please don't suggest regex/other manual .. parsing ..." turns this into code golf. Surely a practical solution serves as an answer. You may find for example the top answer on https://stackoverflow.com/questions/10585029/parse-an-html-string-with-js to help. Parsing is what you'll have to do - one way or another. – Fred Gandt Dec 05 '18 at 10:09

0 Answers0