magento-meanbee-pwa icon indicating copy to clipboard operation
magento-meanbee-pwa copied to clipboard

varnish + serviceworker

Open webdawe opened this issue 7 years ago • 3 comments

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

webdawe avatar Sep 10 '17 11:09 webdawe

@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

tgerulaitis avatar Sep 11 '17 08:09 tgerulaitis

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

webdawe avatar Sep 11 '17 08:09 webdawe

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!

viable-hartman avatar Jun 13 '19 20:06 viable-hartman