Домашняя страница моего сайта была кэширована. Проблема в том, что я не могу его обновить. Упомянутое кэширование связано только с Android устройствами - iOS регулярно получает данные с сервера.
Device: Samsung S10e
Browser: Chrome
Кэшируется только домашняя страница. Когда пользователь использует ссылку перенаправления на веб-сайте, все возвращается к нормальному состоянию - пользователь может видеть обновленную, более новую версию страницы.
Конфигурация PWA:
sw. js файл:
var cacheName = 'c';
const dynamicCacheName = 'c';
self.addEventListener('install', function(e) {
console.log('[ServiceWorker] Install');
e.waitUntil(
caches.open(cacheName).then(function(cache) {
console.log('[ServiceWorker] Caching app shell');
cache.addAll([
'/js/lazysizes.min.js',
]);
})
);
});
self.addEventListener('fetch', function(event) {
event.respondWith(
caches.match(event.request).then(function(response) {
return response || fetch(event.request);
})
);
});
Начало PWA:
const check = () => {
if (!('serviceWorker' in navigator)) {
throw new Error('No Service Worker support!')
}
if (!('PushManager' in window)) {
throw new Error('No Push API Support!')
}
}
const registerServiceWorker = async () => {
const swRegistration = await navigator.serviceWorker.register("/js/sw.js")
return swRegistration
}
const requestNotificationPermission = async () => {
const permission = await window.Notification.requestPermission()
// Propagating permission
saveUserPermissionToTheDatabse(permission);
}
const main = async () => {
check()
const swRegistration = await registerServiceWorker()
const permission = await requestNotificationPermission()
}
main();
nginx .conf:
upstream local_server {
server web:8001;
}
server {
listen 80;
server_name www.website.com;
return 301 https://website.com$request_uri;
}
server {
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/website.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/website.com/privkey.pem;
server_name www.website.com;
}
server {
listen 80;
server_name website.com;
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
location / {
return 301 https://$host$request_uri;
}
location /static/ {
return 301 https://$host$request_uri;
}
location /media/ {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl http2;
server_name website.com;
client_max_body_size 80M;
client_body_buffer_size 8000M;
ssl_certificate /etc/letsencrypt/live/website.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/website.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_types text/plain application/javascript text/css application/json application/x-javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon;
location /sw.js {
add_header Access-Control-Allow-Origin "*";
add_header Cache-Control "public";
expires -1;
alias /js/sw.js;
}
location / {
proxy_pass http://local_server;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
location /static {
add_header Access-Control-Allow-Origin "*";
add_header Cache-Control "public";
expires 2h;
alias /static;
}
location /media {
add_header Access-Control-Allow-Origin "*";
add_header Cache-Control "public";
expires 2h;
alias /media;
}
}