Skip to content

Commit 50a1076

Browse files
change in sw.stub
1 parent bfd59f7 commit 50a1076

File tree

2 files changed

+94
-18
lines changed

2 files changed

+94
-18
lines changed

src/stubs/pwa_app/manifest.stub

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,46 @@
66
"description": "Laravel PWA APP",
77
"display": "fullscreen",
88
"theme_color": "#6777ef",
9+
"orientation": "portrait-primary",
910
"icons": [
1011
{
11-
"src": "logo.PNG",
12+
"src": "logo.png",
13+
"sizes": "72x72",
14+
"type": "image/png",
15+
"purpose": "any maskable"
16+
},
17+
{
18+
"src": "logo.png",
19+
"sizes": "96x96",
20+
"type": "image/png",
21+
"purpose": "any maskable"
22+
},
23+
{
24+
"src": "logo.png",
25+
"sizes": "144x144",
26+
"type": "image/png",
27+
"purpose": "any maskable"
28+
},
29+
{
30+
"src": "logo.png",
31+
"sizes": "152x152",
32+
"type": "image/png",
33+
"purpose": "any maskable"
34+
},
35+
{
36+
"src": "logo.png",
37+
"sizes": "192x192",
38+
"type": "image/png",
39+
"purpose": "any maskable"
40+
},
41+
{
42+
"src": "logo.png",
43+
"sizes": "384x384",
44+
"type": "image/png",
45+
"purpose": "any maskable"
46+
},
47+
{
48+
"src": "logo.png",
1249
"sizes": "512x512",
1350
"type": "image/png",
1451
"purpose": "any maskable"

src/stubs/pwa_app/sw.stub

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,56 @@
1-
{
2-
"name": "Laravel PWA APP",
3-
"short_name": "PWA",
4-
"start_url": "/index.php",
5-
"background_color": "#6777ef",
6-
"description": "Laravel PWA APP",
7-
"display": "fullscreen",
8-
"theme_color": "#6777ef",
9-
"icons": [
10-
{
11-
"src": "logo.PNG",
12-
"sizes": "512x512",
13-
"type": "image/png",
14-
"purpose": "any maskable"
15-
}
16-
]
17-
}
1+
const preLoad = function () {
2+
return caches.open("offline").then(function (cache) {
3+
// caching index and important routes
4+
return cache.addAll(filesToCache);
5+
});
6+
};
7+
8+
self.addEventListener("install", function (event) {
9+
event.waitUntil(preLoad());
10+
});
11+
12+
const filesToCache = [
13+
'/',
14+
'/offline.html'
15+
];
16+
17+
const checkResponse = function (request) {
18+
return new Promise(function (fulfill, reject) {
19+
fetch(request).then(function (response) {
20+
if (response.status !== 404) {
21+
fulfill(response);
22+
} else {
23+
reject();
24+
}
25+
}, reject);
26+
});
27+
};
28+
29+
const addToCache = function (request) {
30+
return caches.open("offline").then(function (cache) {
31+
return fetch(request).then(function (response) {
32+
return cache.put(request, response);
33+
});
34+
});
35+
};
36+
37+
const returnFromCache = function (request) {
38+
return caches.open("offline").then(function (cache) {
39+
return cache.match(request).then(function (matching) {
40+
if (!matching || matching.status === 404) {
41+
return cache.match("offline.html");
42+
} else {
43+
return matching;
44+
}
45+
});
46+
});
47+
};
48+
49+
self.addEventListener("fetch", function (event) {
50+
event.respondWith(checkResponse(event.request).catch(function () {
51+
return returnFromCache(event.request);
52+
}));
53+
if(!event.request.url.startsWith('http')){
54+
event.waitUntil(addToCache(event.request));
55+
}
56+
});

0 commit comments

Comments
 (0)