Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f6afec2
strore manifest info in indexeddb, implement swap cache
segios Mar 10, 2020
f27ba88
fix url in progress event
segios Mar 17, 2020
bf00c38
change this to self in update function
segios Mar 17, 2020
012fbb3
check for only-if-cached flag
segios Mar 17, 2020
ba27d79
chcek for only-if-cached flag, chcek for origin
segios Mar 17, 2020
6041eaa
combine cheks when skip request in one place
segios Mar 19, 2020
bf565e0
fix init cache in first install
segios Mar 19, 2020
fc94caa
update logging, call update on active
segios Mar 21, 2020
6a9eca7
refactor to async await, simplify manifest update logic
segios Apr 7, 2020
8d74402
remove link on repo
segios Apr 7, 2020
59270fd
fix update cache if js file missing
segios Apr 8, 2020
20daadb
Update README.md
segios Apr 8, 2020
661921c
Update README.md
segios Apr 8, 2020
9330e73
Update README.md
segios Apr 8, 2020
19b1591
extract getManifetsUrl
segios Apr 9, 2020
8995c5a
setup serviceworler even if no manifet attribute
segios Apr 9, 2020
f18bd78
Merge branch 'master' of https://github.com/segios/jakecache
segios Apr 9, 2020
481b1f2
return temp check to update from origin file
segios Apr 9, 2020
625c709
return from fromCache and update if no cache exists
segios Apr 13, 2020
446a0f0
add "idb-keyval-iife.js" to cache
segios Apr 14, 2020
5f200c5
normilize navigating url while checking in cache
segios Apr 14, 2020
f6ed41d
fix setup Cache status in offline
segios Apr 30, 2020
596de39
fix autoupdate path; swith autoupdate on by default; improve detectio…
segios May 6, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 84 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,91 @@ NETWORK:
*
```

1. Include ``jakecache.js`` on your page, maybe via ```<script src="jakecache.js"></script>```
1. sample setup
```
function injectJakeCacheScript() {
var s = document.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = '@Url.Content("~/jakecache.js")';
var ss = document.getElementsByTagName('script')[0];
ss.parentNode.insertBefore(s, ss);
}

function setUpCachehandlers() {
if (!('serviceWorker' in navigator)) {
console.log('no serviceWorker');
return;
}

if (!window.jakeCache) {
setTimeout(setUpCachehandlers, 500);
return;
}

window.jakeCache.addEventListener('downloading', function (ev) {
console.log('JakeCache downloading');

});

window.jakeCache.addEventListener('cached', function (ev) {
console.log('JakeCache cached');

});

window.jakeCache.addEventListener('sw-not-attached', function (ev) {
console.log('JakeCache Service worker not attached !!!');

});

window.jakeCache.addEventListener('checking', function (ev) {
console.log('JakeCache checking');

});

window.jakeCache.addEventListener('updateready', function (ev) {
console.log('JakeCache updateready');
window.jakeCache.swapCache();
});

window.jakeCache.addEventListener('updated', function (ev) {
console.log('JakeCache updated');
var url = window.location.href;

// reload to root of application
if (window.location.href.indexOf('#') > 0) {
url = window.location.href.substr(0, window.location.href.indexOf('#')) ;
}
if (url && !url.endsWith('/')) {
url += '/';
}
window.location = url;
});

window.jakeCache.addEventListener('error', function (ev) {
console.log(ev.message);
});

console.log('jakeCache handlers were setup');
}

if ('serviceWorker' in navigator) {
injectJakeCacheScript();
setUpCachehandlers();
}

```
2. Add ```<html manifest="app.manifest">``` to your HTML.
3. That's it! Your website is now Jake-enabled!
3. If name of the manifest is different change it in 'jakecahce-sw.js'
```
const manifestName = 'app.manifest';
```
4. optional parameter in 'jakecahce-sw.js'
```
const isAutoUpdate = false;
```
Means autoupdate cache without message to SwapCahce
5. That's it! Your website is now Jake-enabled!

## License

Expand Down
76 changes: 76 additions & 0 deletions dist/idb-keyval-iife.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
var idbKeyval = (function (exports) {
'use strict';

class Store {
constructor(dbName = 'keyval-store', storeName = 'keyval') {
this.storeName = storeName;
this._dbp = new Promise((resolve, reject) => {
const openreq = indexedDB.open(dbName, 1);
openreq.onerror = () => reject(openreq.error);
openreq.onsuccess = () => resolve(openreq.result);
// First time setup: create an empty object store
openreq.onupgradeneeded = () => {
openreq.result.createObjectStore(storeName);
};
});
}
_withIDBStore(type, callback) {
return this._dbp.then(db => new Promise((resolve, reject) => {
const transaction = db.transaction(this.storeName, type);
transaction.oncomplete = () => resolve();
transaction.onabort = transaction.onerror = () => reject(transaction.error);
callback(transaction.objectStore(this.storeName));
}));
}
}
let store;
function getDefaultStore() {
if (!store)
store = new Store();
return store;
}
function get(key, store = getDefaultStore()) {
let req;
return store._withIDBStore('readonly', store => {
req = store.get(key);
}).then(() => req.result);
}
function set(key, value, store = getDefaultStore()) {
return store._withIDBStore('readwrite', store => {
store.put(value, key);
});
}
function del(key, store = getDefaultStore()) {
return store._withIDBStore('readwrite', store => {
store.delete(key);
});
}
function clear(store = getDefaultStore()) {
return store._withIDBStore('readwrite', store => {
store.clear();
});
}
function keys(store = getDefaultStore()) {
const keys = [];
return store._withIDBStore('readonly', store => {
// This would be store.getAllKeys(), but it isn't supported by Edge or Safari.
// And openKeyCursor isn't supported by Safari.
(store.openKeyCursor || store.openCursor).call(store).onsuccess = function () {
if (!this.result)
return;
keys.push(this.result.key);
this.result.continue();
};
}).then(() => keys);
}

exports.Store = Store;
exports.get = get;
exports.set = set;
exports.del = del;
exports.clear = clear;
exports.keys = keys;

return exports;

}({}));
Loading