You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pass an Object to `Pokedex.init()` in order to configure it. Available options: `protocol`, `hostName`, `versionPath`, `cache`, `timeout`(ms), and `cacheImages`.
68
-
Any option is optional :smile:. All the default values can be found [here](https://github.com/PokeAPI/pokeapi-js-wrapper/blob/master/src/config.js#L3-L10)
69
+
Any option is optional :smile:. All the default values can be found [here](https://github.com/PokeAPI/pokeapi-js-wrapper/blob/master/src/config.js#L3-L11)
69
70
70
71
```js
71
72
constcustomOptions= {
@@ -74,7 +75,8 @@ const customOptions = {
74
75
versionPath:"/api/v2/",
75
76
cache:true,
76
77
timeout:5*1000, // 5s
77
-
cacheImages:true
78
+
cacheImages:true,
79
+
swLocation:'/'
78
80
}
79
81
constpokedex=awaitPokedex.init(customOptions);
80
82
```
@@ -86,14 +88,22 @@ Pokeapi.co serves its Pokemon images through [Github](https://github.com/PokeAPI
86
88
`pokeapi-js-wrapper` enables browsers to cache all these images by:
87
89
88
90
1. enabling the config parameter `cacheImages`
89
-
2. serving [our service worker](https://raw.githubusercontent.com/PokeAPI/pokeapi-js-wrapper/master/src/pokeapi-js-wrapper-sw.js) from the root of your project
91
+
2. serving [our service worker](https://raw.githubusercontent.com/PokeAPI/pokeapi-js-wrapper/master/test/pokeapi-js-wrapper-sw.js) from the root of your project
90
92
91
93
In this way when `pokeapi-js-wrapper`'s `Pokedex` is initialized it will install and start the Service Worker you are serving at the root of your server. The Service Worker will intercept all the calls your HTML/CSS/JS are making to get PokeAPI's images and will cache them.
92
94
93
95
It's fundamental that you download the Service Worker [we provide](https://raw.githubusercontent.com/PokeAPI/pokeapi-js-wrapper/master/src/pokeapi-js-wrapper-sw.js)_(Right Click + Save As)_ and you serve it from the root of your project/server. Service Workers in fact cannot be installed from a domain different than yours.
94
96
95
97
A [basic example](https://github.com/PokeAPI/pokeapi-js-wrapper/blob/master/test/example-sw.html) is hosted [here](https://pokeapi.github.io/pokeapi-js-wrapper/test/example-sw.html).
96
98
99
+
### Caching methods
100
+
101
+
```js
102
+
awaitP.getCacheLength() // Get how many objects are cached
103
+
awaitP.clearCache() // Remove all entries
104
+
awaitP.invalidateCache() // Remove only stale entries
105
+
```
106
+
97
107
## Tests
98
108
99
109
`pokeapi-js-wrapper` can be tested using two strategies. One is with Node, since this package works with Node, and the other with a browser.
@@ -102,7 +112,7 @@ A [basic example](https://github.com/PokeAPI/pokeapi-js-wrapper/blob/master/test
102
112
npm test
103
113
```
104
114
105
-
Or open `/test/test.html` in your browser. A live version can be found at[`gh-pages`](https://pokeapi.github.io/pokeapi-js-wrapper/test/test.html)
115
+
Or open `test/test.html` in your browser after serving the project with `npm run serve`. A live version can be found on the project[`gh-pages`](https://pokeapi.github.io/pokeapi-js-wrapper/test/test.html)
0 commit comments