Code Monkey home page Code Monkey logo

Comments (16)

DustinJSilk avatar DustinJSilk commented on June 8, 2024 1

ok cool, i'll get this setup and test it out on my staging environment today

from qwik.

PatrickJS avatar PatrickJS commented on June 8, 2024 1

@DustinJSilk if you need a fix right away before the next release you can do this in entry.ssr.tsx for any scripts you need. the performance during ssr won't be as great so there are trade-offs until we add nonce support

image

^ fix the typo in my screenshot

from qwik.

DustinJSilk avatar DustinJSilk commented on June 8, 2024 1

Im closing this issue since it is solved by the fact that the service worker spec doesn't cache service worker files in the browser and the PrefetchServiceWorker doesn't change with each build so it is safe to cache in a CDN.

The only thing to note is that future changes to the PrefetchServiceWorker might require some users to evict their prefetch-service-worker.js file from their CDN to reflect changes

from qwik.

DustinJSilk avatar DustinJSilk commented on June 8, 2024

This seems related to #6302 and also some of the issues here #3777.

from qwik.

PatrickJS avatar PatrickJS commented on June 8, 2024

Where are you deploying your qwik app? Aws, cloudflare, vercel, gcp, other?

from qwik.

DustinJSilk avatar DustinJSilk commented on June 8, 2024

Cloud Run on GCP. I have a CDN in place that caches all static files.

from qwik.

PatrickJS avatar PatrickJS commented on June 8, 2024

service-worker.js spec ignores caching policy for this reason. We have another version of service-worker for MFE that we haven't documented by should be more agnostic so won't require updating

from qwik.

DustinJSilk avatar DustinJSilk commented on June 8, 2024

I see, it looks like the below adds a Cache-Control header to the service-worker.js, which causes it to cache in the CDN which means it doesnt update in the browser until the CDN entry expires.

const { router, notFound, staticFile } = createQwikCity({
  // ...
  static: {
    cacheControl: 'public, max-age=31557600',
  },
)}

from qwik.

PatrickJS avatar PatrickJS commented on June 8, 2024

yeah, the cdn might be caching it but the browser won't follow the cache spec. on your cdn you can add a setting to ignore caching the service-worker.js or clear the cache for it on deploys

from qwik.

DustinJSilk avatar DustinJSilk commented on June 8, 2024

Unfortunately GCP CDN doesn't allow you to ignore a specific file, i'd need to either invalidate the entry with each deploy or remove the Cache-Control header from the service-worker.js file somehow.

EDIT

Looks like i can bypass the CDN if i add a custom header to the service-worker.js file, that should be the easiest solution on GCP

^ actually thats not possible in hindsight

from qwik.

PatrickJS avatar PatrickJS commented on June 8, 2024

@DustinJSilk ok @thejackshelton is making an example app but it should be as easy as
replacing
<ServiceWorkerRegister />
with

<PrefetchServiceWorker />

in your root.tsx

from qwik.

DustinJSilk avatar DustinJSilk commented on June 8, 2024

Ok great! It looks like this will embed the symbol files in the HTML and pass it through to the service worker to then be prefetched.

Are there any draw backs in performance to using this approach as opposed to the regular service worker when it isnt cached by the CDN?

Thanks for your time!

from qwik.

PatrickJS avatar PatrickJS commented on June 8, 2024

no drawbacks 👍 this is the new way to do it which will also works for microfrontends

from qwik.

PatrickJS avatar PatrickJS commented on June 8, 2024

ok one thing about this (we need to fix) is that base is set to /build/ so assuming you didn't set base in your ssr.entry.tsx file then it should be fine. if it's different then you have to set the new value in the component

from qwik.

DustinJSilk avatar DustinJSilk commented on June 8, 2024

Ah actually, the PrefetchServiceWorker doesnt support a nonce property like the ServiceWorkerRegister component.

from qwik.

PatrickJS avatar PatrickJS commented on June 8, 2024

yeah we need to add that

from qwik.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.