{"id":16723230,"url":"https://github.com/martinkr/lakka","last_synced_at":"2025-03-17T01:31:28.842Z","repository":{"id":10829327,"uuid":"67145049","full_name":"martinkr/Lakka","owner":"martinkr","description":"lakka. An asynchronous request accelerator for JSON, text and HTML requests.","archived":false,"fork":false,"pushed_at":"2025-03-14T08:33:02.000Z","size":632,"stargazers_count":20,"open_issues_count":13,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-14T09:33:23.964Z","etag":null,"topics":["accelerator","ajax","architecture","asynchronous","cache","fetch","front-end","json","lakka","localstorage","performance","request","xhr","xmlhttprequest"],"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/martinkr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2016-09-01T15:47:29.000Z","updated_at":"2024-06-25T15:31:11.000Z","dependencies_parsed_at":"2024-08-28T10:47:12.140Z","dependency_job_id":"53f0a1dc-d297-40d4-b6de-a65bd3759c86","html_url":"https://github.com/martinkr/Lakka","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinkr%2FLakka","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinkr%2FLakka/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinkr%2FLakka/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinkr%2FLakka/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/martinkr","download_url":"https://codeload.github.com/martinkr/Lakka/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243836015,"owners_count":20355615,"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":["accelerator","ajax","architecture","asynchronous","cache","fetch","front-end","json","lakka","localstorage","performance","request","xhr","xmlhttprequest"],"created_at":"2024-10-12T22:37:27.761Z","updated_at":"2025-03-17T01:31:27.962Z","avatar_url":"https://github.com/martinkr.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lakka [![Build Status](https://travis-ci.org/martinkr/Lakka.svg?branch=master)](https://travis-ci.org/martinkr/Lakka)\nlakka. An asynchronous request accelerator.\n\nlakka is an accelerator for asyncronous requests. It works by caching the request's response in your users local storage. It caches JSON, text and HTML requests and considers the ```Cache-Control``` and ```Expires``` Headers of your requests and responses.\nUsualy, the content of an AJAX-request does not change so often. In the best case, the backend-environemnt either caches them or responds with a \"not-modified\"-like header. But the client still need to wait for this response and the network roundtrip + response time + connection speed makes your website feels \"slow\". This is where ```lakka``` enhances your website's snappiness: no more waiting, instant responses!\n\n## Installation\n\nInstall from npm ```$ yarn add lakka```\n\n## Quick start\n\nAdd  ```dist/wrapper/lakka.js``` to your project.\n\n## Core Concept\n\nBasically you need to call two functions:\n- ```before()``` with the uri before making your request\n- ```after()``` with the response afterwards\n\n#### .before()\n\nCall this function before the actual request. It checks the cache and returns a fresh cache item or throws an error.\n\n#### .after()\n\nCall this after the actual request. Checks the response and store it at the cache. Returns the cache item or throws an error.\n\n## UMD-Module: ```lakka```\n\nThis is an UMD-Module working in your browser, server, requirejs, browserify, commonjs or nodejs setup.\nLoad ```./dist/lakka.js``` to use the lakka accelerator in your code. This  will give you access to the complete lakka-API. It exposes ```window.lakka```for your convienence.\n\n## Examples\n\nTake a look ```example``` folder:\n\n#### ```example/xmlhttprequest.js```\n\nFor a simple example how to use ```lakka``` with  ```window.XMLHTTPRequest()```\n\n#### ```example/fetch.js```\n\nFor a simple example how to use ```lakka``` with ```window.fetch()```\n\n## Configuration\n\nLakka let's you define basic options:\n\n- ```exclude```: Adds a regular-expressions to ignore certain URIs. This can be part of the configuration object or directly set using ``.ignore()```. If an URI matches an ```exclude``` and ```include```pattern, the ```exclude```pattern takes precedence and the URI will be ignored. Default: empty\n- ```include```: Adds a regular-expressions to include certain URIs. This can be part of the configuration object or directly set using ``.recognize()```. If this is set, all non-matching URIs will be ignored. Default: empty\n- ```minutes```: sets the time a cache item is considered \"fresh\" if the response does not contain a ```Cache-Control Header``` or  ```Expires Header```. Default: 60 minutes\n\n## API\n\n### ```ignore(String|RegEx)```\n\nAdds an ignore pattern (a string / RegEx) to the existing / default configuration. URIs matching this pattern will be ignored by lakka and passed throught to the remote location.\n\n#### Arguments\n\n- *String|RegEx*: The pattern to look for\n\n### ```recognize(String|RegEx)```\n\nAdds an include pattern (a string / RegEx) to the existing / default configuration. URIs matching this pattern will be recognized and handled by lakka. If none is set, all URIs will be handled.\n\n#### Arguments\n\n- *String|RegEx*: The pattern to look for\n\n### ```time(Number)```\n\nSets the minutes (Number) we should cache items for. Defaut value is 60 minutes. It will be overwritten by the ```max-age``` - value of the response's ```Cache-Control Header``` or the response's ```Expires Header```.\n\n#### Arguments\n\n- *Number*: The value the default caching time\n\n### ```configuration(Object)```\n\nDynamically merge a configuration object into the current / default configuration object. ```include``` and ```exclude``` will be merged, ```minutes``` will be replaced.\n\n#### Arguments\n\n- *Object*: A configuration object\n\n```JavaScript\n{\n  \"include\":[\"/include-me/\"],\n  \"exclude\":[\"/exclude-me/\"],\n  \"minutes\": 120\n}\n```\n\n### ```after()```\nCall this after the actual request. Checks the response and store it at the cache. Returns the cache item or an error.\n\n* Checks the ```status code``` for success or throws an error.\n* Checks the ```include```and ```exclude```patterns to see if this should be handled by lakka or throws an error.\n* Checks for a cachable ```Cache-Control Header``` or throws an error.\n\t- Cachable: ```public```, ```private```, ```Immutable```, ```proxy-revalidate```\n\t- Non-cachable ```must-revalidate```, ```no-cache```, ```no-store```,\n* Checks the \"Content-Type\" or throws an error.\n\t- Valid content types are: ```application/json```, ```text/x-json```, ```text/plain```, ```text/html```\n* Checks the ```Expires Header``` and the ```Cache-Control Header``` to see if the content is not already stale or throws an error.\n* Creates and saves the cache item\n* Returns the cache item or the thrown error\n#### Arguments\n\n#### Returns\nReturns the cache item or an error if there's no cache-item for this request.\n\n### ```before()```\nCall this before the actual request. Checks for and returns a fresh cache item or an error.\n\n* Checks the ```include```and ```exclude```patterns to see if this should be handled by lakka or throws an error.\n* Checks the ```Cache-Control Header``` or throws an Error\n\t- Cachable: ```public```, ```private```, ```Immutable```, ```proxy-revalidate```\n\t- Non-cachable ```must-revalidate```, ```no-cache```, ```no-store```,\n* Checks the ```Accept Header``` or throws an Error\n\t- Valid content types are: ```application/json```, ```text/x-json```, ```text/plain```, ```text/html``\n* Checks the ```Content Type Header``` or throws an Error\n\t- Valid content types are: ```application/json```, ```text/x-json```, ```text/plain```, ```text/html```\n* Checks there's a fresh item for this URI or throws an Error.\n* Returns the cache item or an error if there's no cache-item for this request.\n\n#### Arguments\n\n#### Returns\nReturns a fresh cache item or an error if there's no cache-item for this request.\n\n### ```remove(String)```\n\nForce clear an item from lakka. Removes all stored content for this URI.\n\n#### Arguments\n\n- *String*: The URI to clear from lakka\n\n### ```flush()```\n\nFlush the lakka cache. Remove all items.\n\n\n\n# Tech Stack\n- Writen in ECMAScript 2018 on ```nodejs v9.0.0``\n- Transpiled```babel v6.26.0```\n- Bundled with ```webpack v3.10.0```\n- 100% code coverage using ```mocha v3.5.0```, ```chai v4.1.1``` and ```nyc v11.2.1```\n\n\n## License\nLicensed under the [MIT license](http://www.opensource.org/licenses/mit-license.php).\n\nCopyright (c) 2016 - 2021 Martin Krause \u003cgithub@mkrause.info\u003e [http://martinkr.github.io)](http://martinkr.github.io)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartinkr%2Flakka","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmartinkr%2Flakka","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartinkr%2Flakka/lists"}