Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Third-party Script Management #180

Open
1 task done
dainemawer opened this issue May 19, 2023 · 0 comments
Open
1 task done

Third-party Script Management #180

dainemawer opened this issue May 19, 2023 · 0 comments

Comments

@dainemawer
Copy link
Contributor

Is your enhancement related to a problem? Please describe.

Third-party scripts are a pain - the solutions are few and far between, and those that do exist are not pretty - so lets explore some:

Service Workers

Service Workers can be a valuable tool for caching assets more aggressively and accessibly than the server can. As all sites run on HTTPS these days (one of the prerequisites for service workers) - we can largely depend on the functionality. Service workers can be used for speedy response times for assets commonly requested on sites.

Serving third-party scripts and assets via CDN is still slower than serving from your server. Using a Service Worker, we can aggressively cache assets that are unlikely to change often: fonts, CSS, js, images, etc.

Google has a great library known as WorkBox that abstracts Service Worker implementation.

Workbox comes with recipes, which are snippets that can be used for everyday tasks that engineers might want to implement; some example could be:

  1. Precaching/prefetching important URL's in the navigation of the site
  2. Caching entire pages
  3. Caching static resources like CSS, js, fonts, images, etc.
  4. Caching Google fonts

Self Hosting

Even though service workers are a form of self-hosting, they're far more dynamic than actual self-hosting. One technique to reduce the latency of third-party scripts is to self-host third-party scripts, removing the network activity needed to actually request the asset before it executes.

There has been advice issued lately regarding the benefits of self-hosting third-party scripts: https://web.dev/efficiently-load-third-party-javascript/#self-host-third-party-scripts - however it has generally been frowned upon because end users might not get the latest updates of a script in question. This is a fair argument, of course.

However, there are plenty of case studies that show major benefits.

This ticket is to potentially explore the pro's and cons of both techniques to see if we can alleviate some of the stress caused by third-party scripts.

Designs

N/A

Describe alternatives you've considered

N/A

Code of Conduct

  • I agree to follow this project's Code of Conduct
@fabiankaegy fabiankaegy changed the title 3P Script Management Third-party Script Management Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants