is it possible to modify service worker cache response headers?

前端 未结 1 558
灰色年华
灰色年华 2021-02-14 03:10

I am trying to mark resources that are being stored in the service worker cache.

I thought it would be possible to add a custom header to the resource that could indica

相关标签:
1条回答
  • 2021-02-14 03:52

    You would have to create a new response to do this:

    fetch('./').then(response => {
      console.log(new Map(response.headers));
    
      const newHeaders = new Headers(response.headers);
      newHeaders.append('x-foo', 'bar');
    
      const anotherResponse = new Response(response.body, {
        status: response.status,
        statusText: response.statusText,
        headers: newHeaders
      });
    
      console.log(new Map(anotherResponse.headers));
    });
    

    Live demo (see the console)

    0 讨论(0)
提交回复
热议问题