Skip to content
This repository has been archived by the owner on Feb 3, 2022. It is now read-only.

varnish + serviceworker #17

Open
webdawe opened this issue Sep 10, 2017 · 3 comments
Open

varnish + serviceworker #17

webdawe opened this issue Sep 10, 2017 · 3 comments

Comments

@webdawe
Copy link

webdawe commented Sep 10, 2017

hi @tgerulaitis ,

I am having troubles when enabling PWA with varnish cache.
image
and shopping cart is getting empty / products removed etc.
Have you heard anything like that?

please let me know.
Anil

@tgerulaitis
Copy link
Member

@webdawe,

Try visiting /serviceworker.js and see if it's returning the service worker JavaScript. I've had service workers fail to install before because Magento wasn't returning the JS, but usually a cache flush fixes the problem.

As for shopping cart being emptied, that shouldn't be related to the service worker. Sounds like there's a session permanence issue, which could be caused by sessions failing to save (check that the file permissions on var/session are sufficient, if you're using files for session storage) or cookies failing to set (check the domain and path settings on the cookie in Magento admin).

Tomas

@webdawe
Copy link
Author

webdawe commented Sep 11, 2017

Hi Tomas,
Thank you!! I thought the same way you said. But these senarios only happens while using varnish as cache. While using full page cache it works all good. I will let you know once I debug further
Anil

@viable-hartman
Copy link

Hi @webdawe ,

The likely cause of your Varnish woes and this extension is your Varnish config and how it handles ".js" files. There are several possible solutions for you regarding this, but here's one that should work for you:

Edit your Varnish VCL file and add something like this near the top of your vcl_recv function but before your javascript handling:

# Rewrite Serviceworker requests. if (req.url ~ "/serviceworker\.js.*") { set req.url = regsuball(req.url, "/serviceworker\.js", "/serviceworker/"); }
Notice I re-write /serviceworker.js to /serviceworker/

That is because I've also changed the frontname in app/code/community/Meanbee/PWA/etc/config.xml from serviceworker.js to simply serviceworker.

Doing this bypasses the Varnish js stuff and allows Magento 1 to render the layout and template file.

Anyway, as I said, that is just one possible solution to your reported issue.

@tgerulaitis nice work and thanks for this, would love to see this idea developed more!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants