Can link rel=preload be made to work with fetch?

后端 未结 3 1057
别跟我提以往
别跟我提以往 2021-01-02 23:09

I have a large JSON blob I would like to have preloaded with my webpage. To do this, I have added

3条回答
  •  没有蜡笔的小新
    2021-01-02 23:32

    Thanks to the discussion in this bug, I got fetch to work with preload in Chromium 67:

    First, add crossorigin attribute to the preload link:

    
    

    Second, add same-origin credentials to the fetch request:

    fetch(url, {credentials: 'same-origin'}).then(response => {
        console.log(response);
    });
    

    Alternatively, you can use XMLHttpRequest instead of fetch (with XHR you don't need to add anything to the request), but only if you're not going to use responseType = 'blob' - it won't work due to another bug.

提交回复
热议问题