If you want to craft the browser default no-internet page according to your design, You can use this libaray. This will library make sure to show your crafted page whenever any document page will not loaded.
- Download the sw.js file
- Put this file inside your project root directory, the name must be same as sw.js
- Create and design a html file which you want to show when internet issue or server unavaialbe. (like no-internet.html)
- Put this file inside your project root directory.
Install the package using npm or script: npm install
Install using npm:
npm i no-internet-web-craft
import NoInternetWebCraft from 'no-internet-web-craft';
const wc = new NoInternetWebCraft('/no-internet.html', '1.0.0')
wc.initWebSocket().then((res) => {
if (res.status === 'success') {
console.log('Service worker activated')
} else {
console.log('Service worker activation failed')
}
})
Put this script tag inside your tag:
<script src="https://www.unpkg.com/no-internet-web-craft@[version]/umd/no-internet-web-craft.min.js"></script>
The NoInternetWebCraft constructor function will available at the global lavel.
const wc = new NoInternetWebCraft('/no-internet.html', '1.0.0')
wc.initWebSocket().then((res) => {
if (res.status === 'success') {
console.log('Service worker activated')
} else {
console.log('Service worker activation failed')
}
})