{"id":15173967,"url":"https://github.com/fastify/fastify-early-hints","last_synced_at":"2025-10-01T10:31:45.628Z","repository":{"id":57233288,"uuid":"312391381","full_name":"fastify/fastify-early-hints","owner":"fastify","description":"Draft plugin of the HTTP 103 implementation","archived":true,"fork":false,"pushed_at":"2024-06-03T20:02:36.000Z","size":137,"stargazers_count":22,"open_issues_count":6,"forks_count":2,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-01-02T09:55:18.021Z","etag":null,"topics":["fastify","fastify-plugin","nodejs"],"latest_commit_sha":null,"homepage":"","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/fastify.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},"funding":{"github":"fastify","open_collective":"fastify"}},"created_at":"2020-11-12T20:44:45.000Z","updated_at":"2024-08-29T17:30:03.000Z","dependencies_parsed_at":"2023-02-14T10:46:49.677Z","dependency_job_id":"ea0322c1-48d4-4a0f-9a25-ac7fa9577aca","html_url":"https://github.com/fastify/fastify-early-hints","commit_stats":{"total_commits":43,"total_committers":10,"mean_commits":4.3,"dds":0.627906976744186,"last_synced_commit":"41613ea0b72f9883e4646446dea44ed7ad4fecea"},"previous_names":["zekth/fastify-early-hints"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastify%2Ffastify-early-hints","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastify%2Ffastify-early-hints/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastify%2Ffastify-early-hints/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastify%2Ffastify-early-hints/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fastify","download_url":"https://codeload.github.com/fastify/fastify-early-hints/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234858930,"owners_count":18897842,"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":["fastify","fastify-plugin","nodejs"],"created_at":"2024-09-27T11:21:25.786Z","updated_at":"2025-10-01T10:31:45.304Z","avatar_url":"https://github.com/fastify.png","language":"JavaScript","readme":"# @fastify/early-hints\n\n\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/)\n![Continuous\nIntegration](https://github.com/fastify/fastify-early-hints/workflows/CI/badge.svg)\n\nDraft proposal of plugin handling the HTTP 103 code.\nBased on : https://github.com/fastify/fastify/issues/2683\n\n## Install\n\n```shell\nnpm i @fastify/early-hints\n```\n\n## Options\n\nYou can pass the following options during the plugin registration:\n\n```js\nawait fastify.register(import('@fastify/early-hints'), {\n  warn: true // default: false\n})\n```\n\n- `warn` : indicates if the plugin should log warnings if invalid values are supplied as early hints\n\n## Usage\n\n### Reply.writeEarlyHints\n\nThis method is used to write early hints with any header you need. It accepts\neither `object` or `Array` of headers and return `Promise`.\n\n```javascript\nconst Fastify = require(\"fastify\");\nconst eh = require(\"@fastify/early-hints\");\n\nconst fastify = Fastify({ logger: true });\nfastify.register(eh);\n\nfastify.get(\"/\", async (request, reply) =\u003e {\n  // object\n  await reply.writeEarlyHints({\n    'Content-Security-Policy': 'style-src: self;',\n    Link: ['\u003c/style.css\u003e; rel=preload; as=style', '\u003c/script.js\u003e; rel=preload; as=script']\n  })\n  // array\n  await reply.writeEarlyHints([\n    { name: 'Content-Security-Policy', value: 'style-src: self;' },\n    { name: 'Link', value: '\u003c/style.css\u003e; rel=preload; as=style' },\n    { name: 'Link', value: '\u003c/script.js\u003e; rel=preload; as=script' },\n  ])\n  return { hello: \"world\" };\n});\n\nconst start = async () =\u003e {\n  try {\n    await fastify.listen({ port: 3000 });\n    fastify.log.info(`server listening on ${fastify.server.address().port}`);\n  } catch (err) {\n    fastify.log.error(err);\n    process.exit(1);\n  }\n};\nstart();\n```\n\nResult\n\n```shell\n$ curl -D - http://localhost:3000    \nHTTP/1.1 103 Early Hints\nContent-Security-Policy: style-src: self;\nLink: \u003c/style.css\u003e; rel=preload; as=style\nLink: \u003c/script.js\u003e; rel=preload; as=script\n\nHTTP/1.1 103 Early Hints\nContent-Security-Policy: style-src: self;\nLink: \u003c/style.css\u003e; rel=preload; as=style\nLink: \u003c/script.js\u003e; rel=preload; as=script\n\nHTTP/1.1 200 OK\ncontent-type: application/json; charset=utf-8\ncontent-length: 17\nDate: Thu, 12 Nov 2020 22:45:54 GMT\nConnection: keep-alive\n\n{\"hello\":\"world\"}\n```\n\n### Reply.writeEarlyHintsLinks\n\nThis method used to write only the `Link` header. It accepts an `Array` and\nreturn `Promise`.\n\n```javascript\nconst Fastify = require(\"fastify\");\nconst eh = require(\"@fastify/early-hints\");\n\nconst fastify = Fastify({ logger: true });\nfastify.register(eh);\n\nfastify.get(\"/\", async (request, reply) =\u003e {\n  await reply.writeEarlyHintsLinks([\n    \"Link: \u003c/style.css\u003e; rel=preload; as=style\",\n    \"Link: \u003c/script.js\u003e; rel=preload; as=script\",\n  ])\n  await reply.writeEarlyHintsLinks([\n    { href: \"//example.com\", rel: \"preload\", as: \"style\" },\n    { href: \"//example.com\", rel: \"preload\", as: \"style\", cors: true },\n    { href: \"//example.com\", rel: \"preconnect\" },\n    { href: \"//example2.com\", rel: \"preconnect\", cors: true },\n    { href: \"//example3.com\", rel: \"preconnect\", cors: \"use-credentials\" },\n  ])\n  return { hello: \"world\" };\n});\n\nconst start = async () =\u003e {\n  try {\n    await fastify.listen({ port: 3000 });\n    fastify.log.info(`server listening on ${fastify.server.address().port}`);\n  } catch (err) {\n    fastify.log.error(err);\n    process.exit(1);\n  }\n};\nstart();\n```\n\nResult\n\n```shell\n$ curl -D - http://localhost:3000    \nHTTP/1.1 103 Early Hints\nLink: \u003c/style.css\u003e; rel=preload; as=style\nLink: \u003c/script.js\u003e; rel=preload; as=script\n\nHTTP/1.1 103 Early Hints\nLink: \u003c/style.css\u003e; rel=preload; as=style\nLink: \u003c/script.js\u003e; rel=preload; as=script\nLink: \u003c//example.com\u003e; rel=preload; as=style\nLink: \u003c//example.com\u003e; rel=preload; as=style; crossorigin\nLink: \u003c//example.com\u003e; rel=preconnect\nLink: \u003c//example2.com\u003e; rel=preconnect; crossorigin\nLink: \u003c//example3.com\u003e; rel=preconnect; crossorigin=use-credentials\n\nHTTP/1.1 200 OK\ncontent-type: application/json; charset=utf-8\ncontent-length: 17\nDate: Thu, 12 Nov 2020 22:45:54 GMT\nConnection: keep-alive\n\n{\"hello\":\"world\"}\n```\n\n## Browser Limitation\n\nCurrently (2022-09-29), only Chrome 103 is supporting `103 Early Hints` and\nChrome will ignore `103 Early Hints` in the following situations.\n\n- Early Hints sent on subresource requests\n- Early Hints sent on iframe navigation\n- Early Hints sent on HTTP/1.1 or earlier\n- Second and following Early Hints\n\nRead more on \u003chttps://chromium.googlesource.com/chromium/src/+/master/docs/early-hints.md#103-early-hints\u003e\n\n## References\n\n- \u003chttps://httpwg.org/specs/rfc8297.html\u003e\n- \u003chttps://www.w3.org/TR/resource-hints/\u003e\n\n## License\n\nLicensed under [MIT](./LICENSE).\n","funding_links":["https://github.com/sponsors/fastify","https://opencollective.com/fastify"],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffastify%2Ffastify-early-hints","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffastify%2Ffastify-early-hints","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffastify%2Ffastify-early-hints/lists"}