modulepreload-koa
v2.1.0
Published
Koa middleware for generating modulepreload link relations for a Link entity-header based on the requested JavaScript modules import graph.
Downloads
2
Maintainers
Readme
modulepreload-koa
Koa middleware for generating modulepreload link relations for a Link entity-header based on the requested JavaScript modules import graph. This will prevent request waterfalls for nested module imports. Supports import maps.
Install
npm i modulepreload-koa
Usage example
import Koa from "koa";
import serve from "koa-static";
import createModulePreloadMiddleware from "modulepreload-koa/createModulePreloadMiddleware.mjs";
const app = new Koa();
const APP_ROOT = "app";
app.use(createModulePreloadMiddleware(APP_ROOT));
app.use(serve(APP_ROOT));
app.listen(3000);
API
createModulePreloadMiddleware(path[, options])
path
{string} Path to the application root directory, eg "app".options
{Object}extensions
{Array<string>} The file extensions to consider for module scripts. Defaults to:["mjs", "js"]
.importMap
{string} Import map string.cache
{Object} A custom (map-like) cache.