18

I used sw precache with service worker.I cached only browser folder in service worker.So that server side rendering not working in service worker.can anyone pls help me to solve this.if ssr working service worker not working and vice versa

below is my 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'
}]
};

Thanks

kamalav
  • 1,190
  • 4
  • 14
  • 31
  • what is the point of the ssr, if you cache entire application? if application already loaded in client with service worker, why you want to load it from server again? if you want to load from ssr always; why are you even caching bundle files? – Okan Aslankan May 29 '18 at 07:22
  • caching is for offline purpose.But for seo purpose I am using angular universal for server side rendering – kamalav May 29 '18 at 08:58

1 Answers1

1

You could choose to only send server-side rendered content to web crawlers so that they can index your page for SEO.

An example configuration using 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;
}
Joshua Chan
  • 1,797
  • 8
  • 16
  • thanks.But it doesn't solve my problem.I am using cachefirst for the files which are contains url like "/^https:\/\/tg\.s3\.rfyfg\.com\//".So,it will not affect ssr. – kamalav May 30 '18 at 04:44
  • I see, I personally solve this issue by only sending SSR to web crawlers like facebookexternalhit, googlebot. You could try that too. – Joshua Chan May 30 '18 at 05:16
  • how can i send this.can you provide an example – kamalav May 30 '18 at 05:25
  • I've edited my answer to provide an example using nginx. – Joshua Chan May 30 '18 at 21:35
  • Thanks Joshua.We have hosted our project in iis using iis node server.I n view page source,we can't see our updated meta and contents after using service worker.But we can post our article to facebook.But we need to get those in view page source.this is my problem – kamalav May 31 '18 at 04:34