LoginSignup
0
0

More than 5 years have passed since last update.

[Service Worker, Cache, fetch] Request の destination

Last updated at Posted at 2019-01-23

仮に静的なファイルは全てキャッシュ優先としたいとする。
request から response を予想したい気がする。

respondWith で何を返すのかを先に決めたいのだ。
ネットワークなのかキャッシュなのか。

sw.js
self.addEventListener('fetch', function(event) {
  console.log(
    event.request.destination,
    event.request.headers.get('accept'),
    event.request.url
  );
  ...
console
style text/css,*/*;q=0.1 http://localhost:5000/static/css/main.b3e7f2db.chunk.css 
script */* http://localhost:5000/static/js/1.fa92c112.chunk.js 
script */* http://localhost:5000/static/js/main.e67a537a.chunk.js 
image image/webp,image/apng,image/*,*/*;q=0.8 http://localhost:5000/static/media/logo.5d5d9eef.svg 
*/*  http://localhost:5000/sw.js 
document text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 http://localhost:5000/help 
unknown */* http://localhost:5000/help

accept はそもそもjsファイルを捉えられない。
urlでマッチングするのはめんどくさい。画像の拡張子とかたくさんある。

request.destination が抽象度が高くて良い

style, script, image, document, unknown, ''

(追記)他にもたくさんあるらしい↓。
https://developer.mozilla.org/en-US/docs/Web/API/RequestDestination
https://fetch.spec.whatwg.org/#concept-request-destination

で、 destination って何者?

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0