liferay / liferay-frontend-projects

A monorepo containing assorted Frontend Infrastructure Team projects
Other
66 stars 67 forks source link

Loading the same ES Module file for multiple portlets #1177

Closed mrtipsytony closed 4 months ago

mrtipsytony commented 8 months ago

👀 Please check the troubleshooting guide before reporting anything. It contains important information on how to fix or diagnose errors.

Issue type (mark with x)

Description

I just have a question. I have portlets that is loading the same ES module (through Liferay.loader.require or aui:script require) many times. Is there a way I can prevent that and make sure only load it once?

Desired behavior: Load the same ES module once since it's shared by multiple portlets

Current behavior: Currently loads the same ES module many times if checked in Network logs

Repro instructions (if applicable):

Other information (environment, versions etc):

izaera commented 8 months ago

Is there a way I can prevent that and make sure only load it once?

It should only load it once. Once a module is fetched from the server and processed by Liferay.Loader it is stored in memory and never fetched or parsed again until the page is refreshed.

Otherwise modules wouldn't be able to have internal state (internal vars) and no stateful module would work.

izaera commented 8 months ago

Currently loads the same ES module many times if checked in Network logs

Can we see those logs? Are these loads for the same page or do they happen after a page reload? Because if it happens after a page reload then what you are seeing is a cache failure, not an issue from the AMD loader.

Meaning that, depending on your DXP server settings, it can be a feature (for example, you definitely want to fetch the JS files every time you access them when you are developing) or an issue (you probably want to cache JS files in production until they change).