This project will let you predict the next user navigation and preload the corresponding document. It's supposed to integrate with Speed Kit.
User Manual Changelog Documented Configuration
nvm use or switch to node 19 manuallynpm install to install dependenciesnpm run prepare to register the pre-commit hooknpm run watch: will start watch mode and a dev server with a test page. Source maps, debug logs and visualisation are available.npm run build: will build the project with development features. Source maps, debug logs and visualisation are available.npm run build:prod: will build and minify the project without development features. Source maps, debug logs and visualisation are not available.npm run build:debug: will build and minify the project without development features. Source maps, debug logs and visualisation are available./dist. This snippet can be copy-pasted into websites to get a live demo. Choose either the dev (predictivePreloading.dev.js) or prod build (predictivePreloading.js).The project can be configured to individual websites. Please refer to the PredictivePreloadConfig.ts for the commented API.
Preloads will by default be reported by calling SpeedKit.preload. The argument is an array of urls:
["/local/link-1", "/local/link-2", "..."]
You can change the preload behaviour by defining custom functions in the config. preloadFunction let you do whatever you want with an array of URL strings. It might be a good idea to check if your own prerequisites are met by defining an own runCondition. Insert logs into the preloadFunction to report what is being preloaded.
You can also define your own runCondition to toggle predictive preloading on your own terms. By default, it's enabled on every page it is included in.
You can test your Predictive Preloading right in the browser. Build the project in dev mode, copy the content dist/predictivePreloading.dev.js and paste it into your Dev Tools console. Then Call predictivePreload(). You can also paste a custom configuration as an argument into the new PredictivePreloading() function call. Use the following configuration to enable debug logs and visualization:
new PredictivePreloading({
logs: true,
visualization: true
})
Please refer to the User Manual for more instructions.
The object containing the preload metadata information is sent via the custom Rum event predictivePreloadingMetadata on leavePage.
preloading Metadata and Failures will be reported in the custom RUM event pp on leavePage, when the config option rum is truthy.
//#if _DEBUG
myDebugCode();
//#endif
src/types/PredictivePreloadConfig.ts.We have some automated unit tests for most parts of this project. Run npm run test:unit to check them. If you run them by calling mocha directly, you may have to add the following options: -r jsdom-global/register --exit. Unit tests should be enabled as pre-commit hooks. In case that didn't happen, please run npm run prepare. Passing unit tests is mandatory for committing and merging.
We have some automated E2E tests to check the functionality of the whole project. Run npm run test:e2e to execute them. Passing E2E tests is mandatory for merging.
We should also test things manually before merging. Here are some helpers for that:
Import createBeacon and add to the predictivePreload function in the predictivePreloading.ts:
document.addEventListener('click', (e) => {
e.preventDefault();
console.log(createBeacon(config, state));
});
We use git flow to publish releases through the Gitlab CI pipeline.
package.jsondevelop.package.json and commitgit checkout prerelease, git pull origin develop and git push.git flow release start v1.2.3git flow release finish 'v1.2.3'git pushgit push --follow-tagsThe Gitlab Pipeline will create a new release:
Please note that the release and release:pre tasks are only to be executed in the CI, not locally.