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

2
  • 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? May 29, 2018 at 7:22
  • caching is for offline purpose.But for seo purpose I am using angular universal for server side rendering
    – kamalav
    May 29, 2018 at 8:58

1 Answer 1

2

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;
}
5
  • 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, 2018 at 4:44
  • I see, I personally solve this issue by only sending SSR to web crawlers like facebookexternalhit, googlebot. You could try that too. May 30, 2018 at 5:16
  • how can i send this.can you provide an example
    – kamalav
    May 30, 2018 at 5:25
  • I've edited my answer to provide an example using nginx. May 30, 2018 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, 2018 at 4:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.