Skip to content

Commit

Permalink
add test & recipe for all origins
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeed committed Dec 14, 2018
1 parent 11af301 commit ab6375a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,20 @@ quicklink({
});
```

**Allow all origins**

Enables all cross-origin requests to be made.

> **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!
```js
quicklink({
origins: true,
// or
origins: []
});
```

## Browser support

The prefetching provided by `quicklink` can be viewed as a [progressive enhancement](https://www.smashingmagazine.com/2009/04/progressive-enhancement-what-it-is-and-how-to-use-it/). Cross-browser support is as follows:
Expand Down
16 changes: 16 additions & 0 deletions test/quicklink.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,22 @@ describe('quicklink tests', function () {
expect(responseURLs).to.include('https://github.githubassets.com/images/spinners/octocat-spinner-32.gif');
});

it('should prefetch all links when allowing all origins', async function () {
const responseURLs = [];
page.on('response', resp => {
responseURLs.push(resp.url());
});
await page.goto(`${server}/test-allow-origin-all.html`);

await page.waitFor(1000);

expect(responseURLs).to.be.an('array');
//=> origins: true
expect(responseURLs).to.include(`${server}/2.html`);
expect(responseURLs).to.include('https://foobar.com/3.html');
expect(responseURLs).to.include('https://example.com/1.html');
expect(responseURLs).to.include('https://github.githubassets.com/images/spinners/octocat-spinner-32.gif');
});

it('should only prefetch links of same origin (default)', async function () {
const responseURLs = [];
Expand Down
27 changes: 27 additions & 0 deletions test/test-allow-origin-all.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Prefetch: Allow All Origins</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" media="screen" href="main.css" />
<script src="https://polyfill.io/v2/polyfill.min.js?features=IntersectionObserver"></script>
</head>
<body>
<a href="https://example.com/1.html">Link 1</a>
<a href="2.html">Link 2</a>
<a href="https://foobar.com/3.html">Link 3</a>
<a href="https://github.githubassets.com/images/spinners/octocat-spinner-32.gif">Spinner</a>
<section id="stuff">
<a href="main.css">CSS</a>
</section>
<a href="4.html" style="position:absolute;margin-top:900px;">Link 4</a>
<script src="../dist/quicklink.umd.js"></script>
<script>
quicklink({
origins: true
});
</script>
</body>
</html>

0 comments on commit ab6375a

Please sign in to comment.