├── .editorconfig ├── .npmignore ├── .babelrc ├── .gitignore ├── webpack.config.js ├── package.json ├── README.md └── src └── Futurelink.vue /.editorconfig: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | npm-debug.log 4 | yarn-error.log 5 | -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["env", { "modules": false }] 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | dist/ 4 | npm-debug.log 5 | yarn-error.log 6 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var webpack = require('webpack'); 3 | const { VueLoaderPlugin } = require('vue-loader') 4 | 5 | module.exports = { 6 | entry: './src/Futurelink.vue', 7 | output: { 8 | path: path.resolve(__dirname, './dist'), 9 | publicPath: '/dist/', 10 | filename: 'futurelink.min.js', 11 | library: 'futurelink', 12 | libraryTarget: 'umd', 13 | }, 14 | mode: process.env.NODE_ENV === 'production' ? 'production' : 'development', 15 | module: { 16 | rules: [ 17 | { 18 | test: /\.vue$/, 19 | loader: 'vue-loader' 20 | }, 21 | { 22 | test: /\.js$/, 23 | loader: 'babel-loader', 24 | exclude: /node_modules/ 25 | } 26 | ] 27 | }, 28 | devtool: '#source-map', 29 | optimization: { 30 | minimize: 'production'.includes(process.env.NODE_ENV) 31 | }, 32 | plugins: [ 33 | new VueLoaderPlugin() 34 | ] 35 | }; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-futurelink", 3 | "description": "Preload links about to be clicked with futurelink.", 4 | "version": "1.2.0", 5 | "author": "Callum Macrae ", 6 | "main": "dist/futurelink.min.js", 7 | "scripts": { 8 | "dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot", 9 | "build": "cross-env NODE_ENV=production webpack --progress --hide-modules", 10 | "prepublish": "npm run build" 11 | }, 12 | "dependencies": { 13 | "futurelink": "^1.0.0", 14 | "vue": "^2.3.3" 15 | }, 16 | "devDependencies": { 17 | "@babel/core": "^7.8.6", 18 | "babel-loader": "^8.0.6", 19 | "babel-preset-env": "^1.5.1", 20 | "cross-env": "^3.0.0", 21 | "css-loader": "^0.25.0", 22 | "mkdirp": "^0.5.2", 23 | "vue-loader": "^15.7.0", 24 | "vue-template-compiler": "^2.3.3", 25 | "webpack": "^4.41.6", 26 | "webpack-cli": "^3.3.11", 27 | "webpack-dev-server": "^3.1.11" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vue-futurelink 2 | 3 | > A vue component to preload links about to be clicked with [futurelink]. 4 | 5 | ## Installation 6 | 7 | ``` 8 | $ npm install --save-dev vue-futurelink 9 | ``` 10 | 11 | ## Usage 12 | 13 | Just load the component and output it into the page, and it will do the rest: it will set up the mouse tracking, hook into vue-router, and output a hidden element to the page. Relies on vue-router. 14 | 15 | ```html 16 | 19 | 20 | 29 | ``` 30 | 31 | I put it below the footer, but in theory it should work anywhere on the page. 32 | 33 | When a page is preloaded, a `preload` event is fired: 34 | 35 | ```html 36 | 39 | 40 | 54 | ``` 55 | 56 | ## Source vs. Dist 57 | 58 | By default, the `main` entry points to the compiled and minified version 59 | of the Vue component. This is typically fine. However, in certain cases, 60 | perhaps using a PR or forked version of this package, you may need to 61 | import the source Vue component directly from the package. To do this, 62 | just append the import with the path to the Vue component: 63 | 64 | ```js 65 | import Futurelink from 'vue-futurelink/src/Futurelink'; 66 | ``` 67 | 68 | > Note: doing this requires that your build system is using 69 | [vue-loader](https://github.com/vuejs/vue-loader) so it can compile the 70 | Vue [SFC](https://github.com/vuejs/vue-loader/blob/master/docs/spec.md). 71 | 72 | ## route.meta.preload 73 | 74 | In some cases, actionable routes shouldn't be preloaded (i.e. `/logout`). 75 | 76 | You can explicitly set the `preload` meta property of a route to 77 | `false` to prevent it from being preloaded: 78 | 79 | ```js 80 | { 81 | path: '/logout', 82 | // ... 83 | meta: { 84 | preload: false, 85 | }, 86 | }, 87 | ``` 88 | 89 | In other cases, routes that can be resource intensive may need more 90 | complex handling to preload additional resources not typically 91 | associated with just mounting a vue component. 92 | 93 | You can also supply the `preload` meta property with a callback 94 | function. This callback is passed two parameters: 95 | 96 | - `path` - (string) The link href value (stripped of any router base path). 97 | - `route` - (Route) The matched route object. 98 | 99 | To prevent the route from being preloaded, the return value of the 100 | callback must explicitly return `false`. Optionally, a `Promise` may 101 | be returned that can ultimately be resolved to a boolean. 102 | 103 | > Note: Any errors or rejections encountered during the callback are intentionally 104 | > caught as preloading is meant to be a passive and non-blocking feature. 105 | > These errors will only be logged to the console if the 106 | > [Vue.config.silent](https://vuejs.org/v2/api/#silent) option is disabled. 107 | 108 | ```js 109 | { 110 | path: '/process-intensive-route', 111 | // ... 112 | meta: { 113 | preload: (path, route) => startFetchingOtherResources(route), 114 | }, 115 | }, 116 | ``` 117 | 118 | 119 | ## License 120 | 121 | Released under the MIT license. 122 | 123 | [futurelink]: https://github.com/SamKnows/futurelink 124 | -------------------------------------------------------------------------------- /src/Futurelink.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 117 | --------------------------------------------------------------------------------