GoogleChromeLabs / GoogleChromeLabs/quicklink

when using window.fetch, even the prefetch Promise is resolved, the resource may still be loading.

Open
#162 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
11.3k
Forks
429
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**
```js
prefetch(url).then(() => {
// the resource may still be loading
})
```

**Expected behavior**

```js
prefetch(url).then(() => {
// the resource have been loaded
})
```

**How to fix**

```js
export function priority(url) {
return window.fetch
? fetch(url, {credentials: `include`}).then(r => {
if (r.ok) return r.arrayBuffer()
throw new Error(r.statusText)
})
: viaXHR(url);
}
```

BTW, why include credentials ?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.