{"id":18971127,"url":"https://github.com/dburles/modulepreload-link-relations","last_synced_at":"2025-04-19T15:06:29.467Z","repository":{"id":198390616,"uuid":"700685624","full_name":"dburles/modulepreload-link-relations","owner":"dburles","description":"Utility for generating modulepreload link relations based on a JavaScript module import graph.","archived":false,"fork":false,"pushed_at":"2024-12-28T02:26:50.000Z","size":42,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-29T09:06:27.281Z","etag":null,"topics":["ecmascript","esm","link","link-rel","link-relations","middleware","modulepreload","preload"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/modulepreload-link-relations","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dburles.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-05T05:04:45.000Z","updated_at":"2024-12-28T02:24:49.000Z","dependencies_parsed_at":null,"dependency_job_id":"b71969a3-6c8d-40dd-b72f-18c734a78caa","html_url":"https://github.com/dburles/modulepreload-link-relations","commit_stats":null,"previous_names":["dburles/modulepreload-link-relations"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dburles%2Fmodulepreload-link-relations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dburles%2Fmodulepreload-link-relations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dburles%2Fmodulepreload-link-relations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dburles%2Fmodulepreload-link-relations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dburles","download_url":"https://codeload.github.com/dburles/modulepreload-link-relations/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249220839,"owners_count":21232421,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ecmascript","esm","link","link-rel","link-relations","middleware","modulepreload","preload"],"created_at":"2024-11-08T14:59:36.945Z","updated_at":"2025-04-16T08:32:44.642Z","avatar_url":"https://github.com/dburles.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# modulepreload-link-relations\n\nA utility for generating [modulepreload](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel/modulepreload) link relations based on a JavaScript modules import graph. This will prevent module request waterfalls.\n\nIt can be used for HTTP server middleware and generating [\\\u003clink\\\u003e](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link) elements in static HTML.\n\nSupports import maps.\n\n## Install\n\n```sh\nnpm i modulepreload-link-relations\n```\n\n## Usage\n\nThis package exports two functions:\n\n- `createResolveLinkRelations`\n  - Returns a function that returns an array of modules that can be preloaded for a specified module. An in-memory cache persists the resulting module import graph.\n- `formatLinkHeaderRelations`\n  - A formatter that can be used to generate link relations for an HTTP [Link](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link) entity-header.\n\n## Example\n\n```js\nimport createResolveLinkRelations from \"modulepreload-link-relations/createResolveLinkRelations.mjs\";\nimport formatLinkHeaderRelations from \"modulepreload-link-relations/formatLinkHeaderRelations.mjs\";\n\nconst resolveLinkRelations = createResolveLinkRelations(\"./app\");\nconst linkRelations = await resolveLinkRelations(\n  // The requested module.\n  \"/lib/a.js\", // (a.js imports b.js, b.js imports c.js, c.js imports d.js)\n); // =\u003e ['/lib/c.js', '/lib/d.js'] // Direct imports aren't included in the result.\n\n// Optionally format the result:\nconst formattedLinkRelations = formatLinkHeaderRelations(linkRelations); // =\u003e \u003c/lib/c.js\u003e; rel=\"modulepreload\", \u003c/lib/d.js\u003e; rel=\"modulepreload\"\n```\n\n## Middleware\n\nMiddleware is available for the following Node.js servers:\n\n- Express - [modulepreload-express](https://github.com/dburles/modulepreload-express)\n- Koa - [modulepreload-koa](https://github.com/dburles/modulepreload-koa)\n\n## API\n\n### `createResolveLinkRelations(path[, options])`\n\n- `path` {string} Path to the application root directory, eg \"./app\".\n- `options` {Object}\n  - `importMap` {string} Import map string.\n  - `cache` {Object} A custom (map-like) cache.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdburles%2Fmodulepreload-link-relations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdburles%2Fmodulepreload-link-relations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdburles%2Fmodulepreload-link-relations/lists"}