hexo-offline is intended to provide offline experience for hexo built static website. It uses ServiceWorker under the hood. Simply install this plugin to your website and it should be offline ready by caching most of static assets.
- vuejs.org: Read Vuejs documentation in the flight.
npm i hexo-offline --save
Once installed, run hexo clean && hexo generate
to activate offline experience.
If the website serves all content from the origin server, you don't have to add any config. Simply install and run hexo clean && hexo generate
.
While hexo-offline aims to provide zero-config offline enhancement to your hexo project, it does offer full list of options control from sw-precache. Simply add your configuration to the root _config.yml
.
# offline config passed to sw-precache.
offline:
maximumFileSizeToCacheInBytes: 5242880
staticFileGlobs:
- public/**/*.{js,html,css,png,jpg,gif,svg,eot,ttf,woff,woff2}
stripPrefix: public
verbose: true
Again, the config is demonstration only and you don't have to copy and paste if you serves all contents from the origin server.
Suppose that you have used two CDN scripts:
- https://cdn.example.com/script-name/script-version.js
- http://cdn.another-example.org/script-name/script-version.css
Add this config to root _config.yml
offline:
runtimeCaching:
- urlPattern: /*
handler: cacheFirst
options:
origin: cdn.example.com
- urlPattern: /*
handler: cacheFirst
options:
origin: cdn.another-example.org
Note:
- As the CDN resources is runtime cached, it means that the resource will be cached only after a user-agent visit the page where the resource is referenced. Therefore, if you have included a CDN resource
example.com/script.js
insome-page.html
only, the user who visitindex.html
only would not haveexample.com/script.js
in cache. - we use
cacheFirst
handler as CDN resources with specific version are not supposed to change in the future.