{"id":27535659,"url":"https://github.com/tugayilik/cachier","last_synced_at":"2025-06-11T21:38:23.255Z","repository":{"id":57157090,"uuid":"106818071","full_name":"tugayilik/cachier","owner":"tugayilik","description":"Allows users to cache their content in Cache Storage and serve it over serviceWorker","archived":false,"fork":false,"pushed_at":"2019-07-22T08:48:23.000Z","size":1037,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-19T06:43:06.592Z","etag":null,"topics":["browser-cache","cache-storage","es6","javascript","progressive-web-app","pwa","service-worker"],"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/tugayilik.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-13T11:50:56.000Z","updated_at":"2020-10-31T14:39:47.000Z","dependencies_parsed_at":"2022-09-03T16:51:17.982Z","dependency_job_id":null,"html_url":"https://github.com/tugayilik/cachier","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tugayilik/cachier","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tugayilik%2Fcachier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tugayilik%2Fcachier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tugayilik%2Fcachier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tugayilik%2Fcachier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tugayilik","download_url":"https://codeload.github.com/tugayilik/cachier/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tugayilik%2Fcachier/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259346670,"owners_count":22843767,"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":["browser-cache","cache-storage","es6","javascript","progressive-web-app","pwa","service-worker"],"created_at":"2025-04-18T19:09:49.330Z","updated_at":"2025-06-11T21:38:23.222Z","avatar_url":"https://github.com/tugayilik.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cachier\n\n\u003chr/\u003e\n\n\u003e **Warning:** Cachier is currently in beta. Only usable in the browsers that has Service Worker and Cache Storage.\n\n\nCache your content on clients browser with Cachier! `Cachier`, uses `Cache Storage` for caching static pages \u0026 files. The `Service Worker` technology serves it over cache for your clients. It also allows clients view offline pages.\n\n**Features**\n\n- The caching process controlled by owner\n- Lightning fast page load\n- Offline page views\n- Less network requests\n\n## Table of Contents\n\n* [Install](#install)\n* [Cachier](#cachier)\n  * [API](#api)\n  * [Options](#options)\n  * [Listeners](#listeners)\n  * [Example](#example)\n* [Contributing](#contributing)\n* [Copyright](#copyright)\n\n## Install\n\nYou can install the library via npm.\n\n```\nnpm install browser-cachier --save\n```\n\nor via yarn:\n\n```\nyarn add browser-cachier\n```\n\n\u003e **Warning:** You need to put [cachier-service-worker.js](https://github.com/tugayilik/cachier/blob/master/cachier-service-worker.js) to your sites `root directory`.\n\n## Cachier\n\n### API\n\n**Warning:** add, remove, update and delete updates the current state of cachier. All events below are returning instance with a promise.\n\n**`new Cachier(config: Object): Cachier`**  \n\nCachier instance takes one argument which is config. The accepted configs described below.\n\n**`cachier.add(urls: Array, callback: Function~response): Cachier`**\n\nAdds provided url list to cache storage. If the provided url is in the cache already, it doesn't add it again. The url list returned from callback.\n\n**`cachier.get(url: String \u003cOptional\u003e, callback: Function~response): Cachier`**\n\nGet cache key from storage. If url argument not sent by user, it gets all otherwise gets single one. As a result it returns true or false according to its existence\n\n**`cachier.update(urls: Array, callback: Function~response): Cachier`**\n\nUpdates the cache content of provided files. The url list returned from callback.\n\n**`cachier.delete(urls: Array, callback: Function~response): Cachier`**\n\nDelete provided url list from cache storage. The url list returned from callback.\n\n**`cachier.clear(callback: Function~response): Cachier`**\n\nEmpty all cache storage. The deleted item list returned from callback.\n\n### Options\n\n**`version {String|Number}`** \n\nSets a version to cache storage. After caching process completed for the first time, it will stay till user clears the cache storage. To overcome this, you can upgrade the version to a greater value. It will clear out of date storages and will set a new one.\n\n**`serviceWorkerPath {String}`**\n\nCachier is using [cachier-service-worker.js](https://github.com/tugayilik/cachier/blob/master/cachier-service-worker.js) to create a layer between network requests and cache. File should be placed on your root directory to observe all scope. This parameter is the location of service worker.\n\n**`debug {Boolean}`**\n\nIf it is true, it gives information on the console about what is going on.\n\n### Listeners\n\n**`stateChange`**  \n\nEverytime change happens on cache storage over API events, stateChange event triggers. It is bound to document. With a simple eventListener you can catch-up state changes. \n\n### Example\n\n```js\nimport Cachier from 'browser-cachier';\n\nlet urlsToCache = ['/dummy/style.css', '/dummy/dummy.json'];\nlet cachier = new Cachier({ version: 1 });\n\ncachier.add(urlsToCache, (response) =\u003e {\n  console.log(response);\n});\n\ncachier.get(response =\u003e {\n  console.log('Get: ', response);\n});\n\ncachier.get('/dummy/style.css', response =\u003e {\n  console.log('Get: ', response);\n});\n\n// Remove specific cache items after 1500ms\nsetTimeout(() =\u003e {\n  cachier.delete(urlsToCache, response =\u003e {\n    console.log('Delete: ', response);\n  });\n}, 1500)\n\n// Remove whole cache on page load\nwindow.onload = function () {\n  cachier.clear();\n};\n\n// Capture state change events\ndocument.addEventListener('stateChange', function (result) {\n    console.log('State: ', result.detail)\n});\n\n```\n\n## Contributing\n\nDo not hesitate to contribute! It is a new born baby and open to ideas.\n\nFor more information, please checkout the [contribution document](https://github.com/tugayilik/cachier/blob/master/CONTRIBUTING.md).\n\n## Copyright\n\nCopyright (c) 2017 tugayilik. See LICENSE.md for further details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftugayilik%2Fcachier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftugayilik%2Fcachier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftugayilik%2Fcachier/lists"}