You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: site/src/api.njk
+39-38Lines changed: 39 additions & 38 deletions
Original file line number
Diff line number
Diff line change
@@ -119,40 +119,40 @@ By default, calls to `prefetch()` are low priority.
119
119
120
120
* Includes a very small fallback for [requestIdleCallback](https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback)
121
121
* Requires `IntersectionObserver` to be supported (see [CanIUse](https://caniuse.com/#feat=intersectionobserver)). We recommend conditionally polyfilling this feature with a service like Polyfill.io:
### Set the request priority for prefetches while scrolling
168
168
169
169
Defaults to low-priority (`rel=prefetch` or XHR). For high-priority (`priority: true`), attempts to use `fetch()` or falls back to XHR.
170
170
171
171
> **Note:** This runs `prefetch(..., true)` with URLs found within the `options.el` container.
172
-
173
-
```js
172
+
{%endmarkdownConvert%}
173
+
{%highlight"js"%}
174
174
quicklink.listen({ priority: true });
175
-
```
176
-
175
+
{%endhighlight%}
176
+
{%markdownConvert%}
177
177
### Specify a custom list of allowed origins
178
178
179
179
Provide a list of hostnames that should be prefetch-able. Only the same origin is allowed by default.
180
180
181
181
> **Important:** You must also include your own hostname!
182
-
183
-
```js
182
+
{%endmarkdownConvert%}
183
+
{%highlight"js"%}
184
184
quicklink.listen({
185
185
origins: [
186
186
// add mine
@@ -192,27 +192,27 @@ quicklink.listen({
192
192
// ...
193
193
]
194
194
});
195
-
```
196
-
195
+
{%endhighlight%}
196
+
{%markdownConvert%}
197
197
### Allow all origins
198
198
199
199
Enables all cross-origin requests to be made.
200
200
201
201
> **Note:** You may run into [CORB](https://chromium.googlesource.com/chromium/src/+/master/services/network/cross_origin_read_blocking_explainer.md) and [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) issues!
202
-
203
-
```js
202
+
{%endmarkdownConvert%}
203
+
{%highlight"js"%}
204
204
quicklink.listen({
205
205
origins: true,
206
206
// or
207
207
origins: []
208
208
});
209
-
```
210
-
209
+
{%endhighlight%}
210
+
{%markdownConvert%}
211
211
### Custom Ignore Patterns
212
212
213
213
These filters run _after_ the `origins` matching has run. Ignores can be useful for avoiding large file downloads or for responding to DOM attributes dynamically.
214
-
215
-
```js
214
+
{%endmarkdownConvert%}
215
+
{%highlight"js"%}
216
216
// Same-origin restraint is enabled by default.
217
217
//
218
218
// This example will ignore all requests to:
@@ -227,21 +227,23 @@ quicklink.listen({
227
227
(uri, elem) => elem.hasAttribute('noprefetch')
228
228
]
229
229
});
230
-
```
231
-
230
+
{%endhighlight%}
231
+
{%markdownConvert%}
232
232
You may also wish to ignore prefetches to URLs which contain a URL fragment (e.g. `index.html#top`). This can be useful if you (1) are using anchors to headings in a page or (2) have URL fragments setup for a single-page application, and which to avoid firing prefetches for similar URLs.
233
233
234
234
Using `ignores` this can be achieved as follows:
235
235
236
-
```js
236
+
{%endmarkdownConvert%}
237
+
{%highlight"js"%}
237
238
quicklink.listen({
238
239
ignores: [
239
240
uri => uri.includes('#')
240
241
// or RegExp: /#(.+)/
241
242
// or element matching: (uri, elem) => !!elem.hash
242
243
]
243
244
});
244
-
```
245
+
{%endhighlight%}
246
+
{%markdownConvert%}
245
247
246
248
## Browser Support
247
249
@@ -262,15 +264,14 @@ A `prefetch` method can be individually imported for use in other projects.<br>
262
264
This method includes the logic to respect Data Saver and 2G connections. It also issues requests thru `fetch()`, XHRs, or `link[rel=prefetch]` depending on (a) the `isPriority` value and (b) the current browser's support.
263
265
264
266
After installing `quicklink` as a dependency, you can use it as follows:
0 commit comments