Refactoring Bacom utils.js / scripts.js for performance and consuming blocks using getLibs #2518
-
Hey folks, I had a question regarding what we might consider best practice for consuming repositories. In an attempt to help reduce the amount of calls, bacom is moving the However, as a consumer we have a few blocks that call getLibs to get the correct path for utilities like Since this is an issue that may be faced by other consuming projects, we thought it best to bring it up in a community discussion. The paths forward as I can see them are as follows:
I think exporting from scripts will be the cleanest, but wanted to see what the community thought. Thank you all for your feedback! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
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.
This is pretty close to what I would put in scripts.js... export const LIBS = (() => {
const { hostname, search } = window.location;
if (!(hostname.includes('.hlx.') || hostname.includes('local'))) return '/libs';
const branch = new URLSearchParams(search).get('milolibs') || 'main';
if (branch === 'local') return 'http://localhost:6456/libs';
return branch.includes('--') ? `https://${branch}.hlx.live/libs` : `https://${branch}--milo--adobecom.hlx.live/libs`;
})(); |
Beta Was this translation helpful? Give feedback.
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.
This is pretty close to what I would put in scripts.js...