Skip to content

Refactoring Bacom utils.js / scripts.js for performance and consuming blocks using getLibs #2518

Discussion options

You must be logged in to vote

We have evolved some of our patterns since we established consumer utils back in 2022. We've learned a lot about side effects and how to use them to our advantage.

  1. I think we can get rid of set / get and only do get. Get is probably not even necessary.
  2. I'd keep utils around for non-critical / non-lcp functions, but only move libs into scripts.js.
  3. I consider using a window object in 2024 as a code smell. There's no reason to do this with ESM.
  4. You're 100% right that we don't like to export out of scripts, but it's probably ok for libs.

This is pretty close to what I would put in scripts.js...

export const LIBS = (() => {
  const { hostname, search } = window.location;
  if (!(hostname.inc…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@JasonHowellSlavin
Comment options

@Brandon32
Comment options

@mokimo
Comment options

@Brandon32
Comment options

Answer selected by JasonHowellSlavin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants