Skip to content

Commit

Permalink
Change version name
Browse files Browse the repository at this point in the history
  • Loading branch information
Babek Naghiyev authored and Babek Naghiyev committed Jan 10, 2021
1 parent b7ed0b9 commit f5c615d
Show file tree
Hide file tree
Showing 4 changed files with 703 additions and 709 deletions.
25 changes: 9 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,25 @@

Easiest caching ever. No need to hard work as ETag or whatever. As easy as drinking a coffee, even easier.

#### 1. Caches only html. Images and other assets should be the concern of browsers


#### 1. Caches only html. Images and other assets should be the concern of browsers

#### 2. First, returns cached version of url.
#### 2. First, returns cached version of url.

#### 3. After that, makes a fetch request on background to that url.

#### 4. If there is any difference between cached and remote html, then updates it on background and sends a message to client
#### 4. If there is any difference between cached and remote html, then updates it on background and sends a message to client

#### 5. When client gets a message to refresh, it can reload the page or load via js (example: jQuery load function)


#### See the example folder for testing it yourself


## Usage

### Service worker file

```
importScripts('https://cdn.jsdelivr.net/gh/nagibaba/easy-service-worker@1.1.4/lib/index.js');
importScripts('https://cdn.jsdelivr.net/gh/nagibaba/easy-service-worker@1.2.0/lib/index.js');
const sw = new EasySW();
Expand Down Expand Up @@ -56,7 +52,6 @@ sw.exclude = (url) => {

### Html part (Client)


```
<script>
if ('serviceWorker' in navigator) {
Expand All @@ -81,30 +76,28 @@ sw.exclude = (url) => {
// response code is 300 or more
}
}
}
</script>
```

| WARNING: Any regenerated strings like csrf tokens may end up with forever reloading. If so, avoid reload function or wrap any regenerated texts inside `<!--EasySWIgnore--> <!--/EasySWIgnore-->`|

| WARNING: Any regenerated strings like csrf tokens may end up with forever reloading. If so, avoid reload function or wrap any regenerated texts inside `<!--EasySWIgnore--> <!--/EasySWIgnore-->`|

## Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.


```
npm run prepublish
```

## Version 1.1.4


## Version 1.2.0

## License

[MIT](https://choosealicense.com/licenses/mit/)
13 changes: 7 additions & 6 deletions example/sw.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
importScripts('https://cdn.jsdelivr.net/gh/nagibaba/[email protected]/lib/index.js');
importScripts(
"https://cdn.jsdelivr.net/gh/nagibaba/[email protected]/lib/index.js",
);

const sw = new EazySW();

sw.CACHENAME = 'default-easy-cache-v1'
sw.CACHENAME = "default-easy-cache-v1";

// resources to be precached
// @default ['/']
sw.precacheResources = ['/'];
sw.precacheResources = ["/"];

// Cache requests including "?"
// @default false
sw.cacheGetRequests = false;

// offline if not cached
// @default '/offline.html'
sw.offlinePage = '/offline.html';

sw.offlinePage = "/offline.html";

// Returns true if you don't want the URL to be cached
// @return boolean
// @param {url} requested url
// @default false
sw.exclude = (url) => {
return false;
}
};
Loading

0 comments on commit f5c615d

Please sign in to comment.