{"id":22092220,"url":"https://github.com/pirxpilot/connect-cachify-static","last_synced_at":"2025-07-24T20:32:08.276Z","repository":{"id":57152643,"uuid":"12910760","full_name":"pirxpilot/connect-cachify-static","owner":"pirxpilot","description":"static (simpler and faster) variant of connect-cachify middleware","archived":false,"fork":false,"pushed_at":"2023-10-16T10:18:29.000Z","size":61,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-11-11T06:12:41.326Z","etag":null,"topics":["express-middleware","middleware"],"latest_commit_sha":null,"homepage":null,"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/pirxpilot.png","metadata":{"files":{"readme":"Readme.md","changelog":"History.md","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":"2013-09-18T01:02:41.000Z","updated_at":"2022-05-14T06:25:14.000Z","dependencies_parsed_at":"2024-06-21T12:57:36.261Z","dependency_job_id":"0aa1dd6b-ff2a-4fe2-a290-d08ad4f73952","html_url":"https://github.com/pirxpilot/connect-cachify-static","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pirxpilot%2Fconnect-cachify-static","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pirxpilot%2Fconnect-cachify-static/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pirxpilot%2Fconnect-cachify-static/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pirxpilot%2Fconnect-cachify-static/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pirxpilot","download_url":"https://codeload.github.com/pirxpilot/connect-cachify-static/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227476143,"owners_count":17779417,"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":["express-middleware","middleware"],"created_at":"2024-12-01T03:08:46.475Z","updated_at":"2024-12-01T03:08:47.262Z","avatar_url":"https://github.com/pirxpilot.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![NPM version][npm-image]][npm-url]\n[![Build Status][build-image]][build-url]\n[![Dependency Status][deps-image]][deps-url]\n\n# connect-cachify-static\n\nstatic (simpler and faster) variant of [connect-cachify][] middleware\n\nAdds `Cache-Control: max-age=31536000` header to all requests with 'cachified' prefix. Prefix is\nbased on the file content and calculated for all files during application startup (which means that\nit won't handle dynamically generated files).\n\nIf you reference cachifieable resources from CSS files you probably also want to use [postcss-cachify].\n\n## Installation\n\n    $ npm install connect-cachify-static\n\n## Options\n\n- `match` - regular expression that determines which files in `root` will be cachified, if omitted\n  the usual suspects are included `.js`, `.css`, `.png`, `.jpg`, and `.gif`\n- `control_headers` - if truthy, the middleware will strip `ETag` and `Last-Modified` headers from the\n  response\n- `format` - function that creates cachified version of the URL - allowed values are `'path'`, `'name'`,\n  or the function that takes `path` and `hash` and creates cachified version of the file URL\n\n## API\n\n`cachify` function is injected in res.locals and thus can be accessed from the template code.\n`cachify` and `filter` can be also retrieved by calling `await helpers()` on the initialized middleware instance\n\n### `cachify(path, integrity)`\n\n- `path` - URL of the resource to be cachified\n- `integrity` - optional - if truthy cachify will generate a tuple `{ path, integrity }`, which can\nbe used to format `\u003cscript\u003e` and `\u003clink\u003e` elements with [subresource integrity][sri] support\n\nIt should be called when generating HTML, CSS etc., in order to create a 'cachified' URL for the\nresource. `cachify` will replace `/path/to/the/file` with cachified version incorporating reasonably unique `{prefix}` generated based on the file content.\n\nThe specific format of the cachified version depends on the `format` parameter:\n\n- `path` *default*\n\n    `/path/to/the/file` -\u003e `/{prefix}/path/to/the/file`\n\n- `name`\n\n    `/path/to/the/file` -\u003e `/path/to/the/{prefix}- file`\n\nYou can also pass a format function:\n\n````javascript\n// this is how default format is implemented\nfunction format(path, prefix) {\n  return '/' + prefix + path;\n}\n\n````\n\nSince using `cachify` will make the browsers to cache the resource for approximately 1 year we need\nto bust the cache whenever the resource content changes.\n\n```jade\nhead\n  //- styles\n  link(rel=\"stylesheet\", href=cachify('/css/style.css'), media=\"screen\")\n  link(rel=\"stylesheet\", href=cachify('/css/print.css'), media=\"print\")\nbody\n  // can be used to pass cachified URLs to client scripts\n  #info(data-icon=cachify('/img/icon.png'))\n  //- scripts\n  script(src=cachify('/script/main.js'), defer)\n\n  //- scripts with SRI support\n  - var c = cachify('/script/main.js', true)\n  script(src=c.path, integrity=c.integrity, crossorigin='anonymous', defer)\n\n```\n\n### `filter(patter)`\n\nreturns an array of cachified paths matching pattern\n\n\n## Usage\n\n```javascript\nvar connect = require('connect');\nvar cachifyStatic = require('connect-cachify-static');\n\nconnect()\n  .use(cachifyStatic(__dirname + '/public'), {\n    match: /\\.js$/ // only javascript files\n  })\n// need static to actually serve the file\nconnect()\n  .use(connect.static(__dirname + '/public'))\n```\n\n# License\n\nMIT\n\n[connect]: http://www.senchalabs.org/connect\n[connect-cachify]: https://www.npmjs.com/package/connect-cachify\n[express]: http://expressjs.com\n[postcss-cachify]: https://www.npmjs.com/package/postcss-cachify\n[minimatch]: https://www.npmjs.com/package/minimatch\n[sri]: https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity\n\n[npm-image]: https://img.shields.io/npm/v/connect-cachify-static\n[npm-url]: https://npmjs.org/package/connect-cachify-static\n\n[build-url]: https://github.com/pirxpilot/connect-cachify-static/actions/workflows/check.yaml\n[build-image]: https://img.shields.io/github/actions/workflow/status/pirxpilot/connect-cachify-static/check.yaml?branch=main\n \n[deps-image]: https://img.shields.io/librariesio/release/npm/connect-cachify-static\n[deps-url]: https://libraries.io/npm/connect-cachify-static\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpirxpilot%2Fconnect-cachify-static","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpirxpilot%2Fconnect-cachify-static","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpirxpilot%2Fconnect-cachify-static/lists"}