18

我将 sw precache 与 service worker 一起使用。我只缓存了 service worker 中的浏览器文件夹。所以服务器端渲染在 service worker 中不起作用。任何人都可以帮我解决这个问题。如果 ssr 工作 service worker 不工作,反之亦然

下面是我的 sw precache config.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'
}]
};

谢谢

4

1 回答 1

1

您可以选择仅将服务器端呈现的内容发送给网络爬虫,以便他们可以为您的页面编制 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;
}
于 2018-05-30T03:31:13.810 回答