我将sw precache与service worker一起使用。我只在服务工作者中缓存了浏览器文件夹。这样服务器端渲染在服务工作者中不起作用。任何人都可以帮我解决这个问题。如果 ssr 工作服务工作者不起作用,反之亦然
下面是我的软件预缓存配置.json
module.exports = {
navigateFallback: '/index.html',
stripPrefix: 'dist/browser',
root: 'dist/browser',
staticFileGlobs: [
'dist/browser/index.html',
'dist/browser/**.js',
'dist/browser/**.css',
'dist/browser/**.ico',
'dist/browser/assets/images/**.jpg',
'dist/browser/assets/images/**.png',
'dist/browser/assets/images/**.gif',
'dist/browser/assets/js/**/**.js',
'dist/browser/assets/js/**.js',
'dist/browser/assets/css/**.css'
],
runtimeCaching: [{
urlPattern: /^https://tg.s3.rfyfg.com//,
handler: 'cacheFirst'
}]
};
谢谢
您可以选择仅将服务器端呈现的内容发送到网络爬虫,以便他们可以索引您的页面以进行 SEO。
使用 nginx 的示例配置:
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_ignore_headers X-Accel-Expires Expires Cache-Control;
if ($http_user_agent ~* "whatsapp|googlebot|yahoo|bingbot|baiduspider|yandex|yeti|yodaobot|gigabot|ia_archiver|facebookexternalhit|twitterbot|developers.google.com|linkedinbot|discordbot|embedly|quora link preview|slackbot|pinterest|vkShare") {
proxy_pass http://localhost:4000; // your server
break;
}
rewrite . /static/index.html last;
}