Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

quicklink

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

quicklink - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

test/1.html

4

.eslintrc.js
module.exports = {
env: {
browser: true,
es6: true
es6: true,
node: true
},
parserOptions: {
sourceType: 'module',
ecmaVersion: 8
},

@@ -9,0 +11,0 @@ extends: 'google',

@@ -1,1 +0,1 @@

var n=function(n){return new Promise(function(e,t){var o=new XMLHttpRequest;o.open("GET",n,!0),o.withCredentials=!0,o.onload=function(){200===o.status?e():t()},o.send(null)})},e=function(n){if("undefined"==typeof document)return!1;var e=document.createElement("link");try{if(e.relList&&"function"==typeof e.relList.supports)return e.relList.supports(n)}catch(n){return!1}}("prefetch")?function(n){return new Promise(function(e,t){if("undefined"!=typeof document){var o=document.createElement("link");o.setAttribute("rel","prefetch"),o.setAttribute("href",n),o.onload=e,o.onerror=t,(document.getElementsByTagName("head")[0]||document.getElementsByName("script")[0].parentNode).appendChild(o)}else t()})}:n,t={},o=function(o,i){return new Promise(function(r){if("connection"in navigator){if(navigator.connection.effectiveType&&/\slow-2g|2g/.test(navigator.connection.effectiveType))return void r();if(navigator.connection.saveData)return void r()}t[o]?r():i&&"high"===i?function(e){return new Promise(function(t,o){void 0===self.fetch?n(e).then(function(){t()}):fetch(e,{credentials:"include"}).then(function(){t()})})}(o).then(function(){r(),t[o]=!0}).catch(function(){}):e(o).then(function(){r(),t[o]=!0}).catch(function(){})})},i=window.requestIdleCallback||function(n){var e=Date.now();return setTimeout(function(){n({didTimeout:!1,timeRemaining:function(){return Math.max(0,50-(Date.now()-e))}})},1)};var r=function(n,e){n.forEach(function(n){o(n,e)})};module.exports=function(n){n=n||{priority:"low"},i(function(){void 0!==n.urls&&n.urls.length>0?r(n.urls,n.priority):function(n){return new Promise(function(e,t){var o=[],i=n.querySelectorAll("a"),r=new IntersectionObserver(function(n){n.forEach(function(n){n.intersectionRatio>0&&o.push(n.target.href)}),e(o)});i.forEach(function(n){r.observe(n)})})}(n.el||document).then(function(e){r(e,n.priority)})})};
var n=function(n){return new Promise(function(t,e){var o=new XMLHttpRequest;o.open("GET",n,!0),o.withCredentials=!0,o.onload=function(){200===o.status?t():e()},o.send(null)})},t=function(n){if("undefined"==typeof document)return!1;var t=document.createElement("link");try{if(t.relList&&"function"==typeof t.relList.supports)return t.relList.supports(n)}catch(n){return!1}}("prefetch")?function(n){return new Promise(function(t,e){if("undefined"!=typeof document){var o=document.createElement("link");o.setAttribute("rel","prefetch"),o.setAttribute("href",n),o.onload=t,o.onerror=e,(document.getElementsByTagName("head")[0]||document.getElementsByName("script")[0].parentNode).appendChild(o)}else e()})}:n,e={},o=function(o,i){return new Promise(function(r){if("connection"in navigator){if(navigator.connection.effectiveType&&/\slow-2g|2g/.test(navigator.connection.effectiveType))return void r();if(navigator.connection.saveData)return void r()}e[o]?r():i&&"high"===i?function(t){return new Promise(function(e,o){void 0===self.fetch?n(t).then(function(){e()}):fetch(t,{credentials:"include"}).then(function(){e()})})}(o).then(function(){r(),e[o]=!0}).catch(function(){}):t(o).then(function(){r(),e[o]=!0}).catch(function(){})})},i=i||function(n){var t=Date.now();return setTimeout(function(){n({didTimeout:!1,timeRemaining:function(){return Math.max(0,50-(Date.now()-t))}})},1)};var r=function(n,t){n.forEach(function(n){o(n,t)})};module.exports=function(n){return new Promise(function(t,e){i(function(){void 0!==n.urls&&n.urls.length>0?(r(n.urls,n.priority),t(n.urls)):function(n){return new Promise(function(t,e){var o=[],i=n.querySelectorAll("a"),r=new IntersectionObserver(function(n){n.forEach(function(n){n.intersectionRatio>0&&o.push(n.target.href)}),t(o)});i.forEach(function(n){r.observe(n)})})}(n.el||document).then(function(e){r(e,n.priority),t(e)})},{timeout:(n=n||{priority:"low",timeout:2e3}).timeout})})};

@@ -1,1 +0,1 @@

!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):n.quicklink=e()}(this,function(){var n=function(n){return new Promise(function(e,t){var o=new XMLHttpRequest;o.open("GET",n,!0),o.withCredentials=!0,o.onload=function(){200===o.status?e():t()},o.send(null)})},e=function(n){if("undefined"==typeof document)return!1;var e=document.createElement("link");try{if(e.relList&&"function"==typeof e.relList.supports)return e.relList.supports(n)}catch(n){return!1}}("prefetch")?function(n){return new Promise(function(e,t){if("undefined"!=typeof document){var o=document.createElement("link");o.setAttribute("rel","prefetch"),o.setAttribute("href",n),o.onload=e,o.onerror=t,(document.getElementsByTagName("head")[0]||document.getElementsByName("script")[0].parentNode).appendChild(o)}else t()})}:n,t={},o=function(o,i){return new Promise(function(r){if("connection"in navigator){if(navigator.connection.effectiveType&&/\slow-2g|2g/.test(navigator.connection.effectiveType))return void r();if(navigator.connection.saveData)return void r()}t[o]?r():i&&"high"===i?function(e){return new Promise(function(t,o){void 0===self.fetch?n(e).then(function(){t()}):fetch(e,{credentials:"include"}).then(function(){t()})})}(o).then(function(){r(),t[o]=!0}).catch(function(){}):e(o).then(function(){r(),t[o]=!0}).catch(function(){})})},i=window.requestIdleCallback||function(n){var e=Date.now();return setTimeout(function(){n({didTimeout:!1,timeRemaining:function(){return Math.max(0,50-(Date.now()-e))}})},1)};var r=function(n,e){n.forEach(function(n){o(n,e)})};return function(n){n=n||{priority:"low"},i(function(){void 0!==n.urls&&n.urls.length>0?r(n.urls,n.priority):function(n){return new Promise(function(e,t){var o=[],i=n.querySelectorAll("a"),r=new IntersectionObserver(function(n){n.forEach(function(n){n.intersectionRatio>0&&o.push(n.target.href)}),e(o)});i.forEach(function(n){r.observe(n)})})}(n.el||document).then(function(e){r(e,n.priority)})})}});
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):n.quicklink=e()}(this,function(){var n=function(n){return new Promise(function(e,t){var o=new XMLHttpRequest;o.open("GET",n,!0),o.withCredentials=!0,o.onload=function(){200===o.status?e():t()},o.send(null)})},e=function(n){if("undefined"==typeof document)return!1;var e=document.createElement("link");try{if(e.relList&&"function"==typeof e.relList.supports)return e.relList.supports(n)}catch(n){return!1}}("prefetch")?function(n){return new Promise(function(e,t){if("undefined"!=typeof document){var o=document.createElement("link");o.setAttribute("rel","prefetch"),o.setAttribute("href",n),o.onload=e,o.onerror=t,(document.getElementsByTagName("head")[0]||document.getElementsByName("script")[0].parentNode).appendChild(o)}else t()})}:n,t={},o=function(o,i){return new Promise(function(r){if("connection"in navigator){if(navigator.connection.effectiveType&&/\slow-2g|2g/.test(navigator.connection.effectiveType))return void r();if(navigator.connection.saveData)return void r()}t[o]?r():i&&"high"===i?function(e){return new Promise(function(t,o){void 0===self.fetch?n(e).then(function(){t()}):fetch(e,{credentials:"include"}).then(function(){t()})})}(o).then(function(){r(),t[o]=!0}).catch(function(){}):e(o).then(function(){r(),t[o]=!0}).catch(function(){})})},i=i||function(n){var e=Date.now();return setTimeout(function(){n({didTimeout:!1,timeRemaining:function(){return Math.max(0,50-(Date.now()-e))}})},1)};var r=function(n,e){n.forEach(function(n){o(n,e)})};return function(n){return new Promise(function(e,t){i(function(){void 0!==n.urls&&n.urls.length>0?(r(n.urls,n.priority),e(n.urls)):function(n){return new Promise(function(e,t){var o=[],i=n.querySelectorAll("a"),r=new IntersectionObserver(function(n){n.forEach(function(n){n.intersectionRatio>0&&o.push(n.target.href)}),e(o)});i.forEach(function(n){r.observe(n)})})}(n.el||document).then(function(t){r(t,n.priority),e(t)})},{timeout:(n=n||{priority:"low",timeout:2e3}).timeout})})}});
{
"name": "quicklink",
"version": "0.0.1",
"version": "0.0.2",
"description": "Faster subsequent page-loads by prefetching in-viewport links during idle time",

@@ -13,6 +13,9 @@ "main": "dist/quicklink.js",

"scripts": {
"lint": "eslint src/*.mjs",
"lint": "eslint src/*.mjs test/*.js",
"lint-fix": "eslint src/*.mjs test/*.js --fix",
"server": "http-server .",
"test": "npm run build && mocha test/bootstrap.js --recursive test",
"build": "microbundle src/index.mjs --no-sourcemap",
"prepare": "npm run -s build",
"release": "cross-var npm run build -s && cross-var git commit -am $npm_package_version && cross-var git tag $npm_package_version && git push && git push --tags && npm publish"
"release": "cross-var npm run build -s && cross-var git commit -am $npm_package_version && cross-var git tag $npm_package_version && git push && git push --tags && npm publish --access public"
},

@@ -28,8 +31,15 @@ "keywords": [

"devDependencies": {
"babel-preset-env": "^1.7.0",
"chai": "^4.2.0",
"cross-var": "^1.1.0",
"eslint": "^5.9.0",
"eslint-config-google": "^0.11.0",
"microbundle": "^0.7.0"
"http-server": "^0.11.1",
"lodash": "^4.17.11",
"microbundle": "^0.7.0",
"mocha": "^5.2.0"
},
"dependencies": {}
"dependencies": {
"puppeteer": "^1.10.0"
}
}

@@ -6,3 +6,3 @@ # quicklink

Quicklink makes subsequent navigations to pages load faster. It:
Quicklink attempts to make navigations to subsequent pages load faster. It:

@@ -14,5 +14,14 @@ * **Detects links within the viewport** (using `IntersectionObsever`)

## Installation
For use with [node](http://nodejs.org) and [npm](https://npmjs.com):
```sh
npm install --save quicklink
```
## Usage
Once initialized, `quicklink` will automatically prefetch URLs for links that are in-viewport during idle time.
Quickstart:

@@ -36,4 +45,44 @@

The above options are best for multi-page sites. Single-page apps have a few options available for using quicklink with a router:
* Call `quicklink()` once a navigation to a new route has completed
* Call `quicklink()` against a specific DOM element / component
* Call `quicklink({urls:[...]})` with a custom set of URLs to prefetch
## API
`quicklink` accepts an optional options object with the following parameters:
* `el`: DOM element to observe for in-viewport links to prefetch
* `urls`: Static array of URLs to prefetch (instead of observing `document` or a DOM element links in the viewport)
* `timeout`: Integer for the `requestIdleCallback` timeout. A time in milliseconds by which the browser must execute prefetching. Defaults to 2 seconds.
* `priority`: String specifying preferred priority for fetches. Defaults to `low`. `high` will attempt to use the `fetch()` API where supported (rather than rel=prefetch)
TODO:
* Explore detecting file-extension of resources and using [rel=preload](https://w3c.github.io/preload/) for `high` priority fetches
* Explore using [Priority Hints](https://github.com/WICG/priority-hints) for importance hinting
## Polyfills
`quicklink`:
* Includes a very small fallback for [requestIdleCallback](https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback)
* Requires `IntersectionObserver` to be supported (see [CanIUse](https://caniuse.com/#feat=intersectionobserver)). We recommend conditionally polyfillng this feature with a service like Polyfill.io:
```html
<script src="https://polyfill.io/v2/polyfill.min.js?features=IntersectionObserver"></script>
```
## Recipes
**Set a custom timeout for prefetching resources**
Defaults to 2 seconds (via `requestIdleCallback`). Here we override it to 4 seconds:
```js
quicklink({
timeout: 4000
});
```
**Set the DOM element to obseve for in-viewport links**

@@ -44,3 +93,3 @@

```js
let elem = document.getElementById('stuff');
const elem = document.getElementById('carousel');
quicklink({

@@ -57,3 +106,3 @@ el: elem

quicklink({
urls: ['2.html','4.html']
urls: ['2.html','3.html', '4.js']
});

@@ -65,3 +114,3 @@ ```

Defaults to low-priority (`rel=prefetch` or XHR). For high-priority,
attempts to use fetch() or falls back to XHR.
attempts to use `fetch()` or falls back to XHR.

@@ -68,0 +117,0 @@ ```js

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc