We are building Lightning Web Components for a Community and we're leveraging a 3rd party library to help with some charts/widgets. Each chart is it's own component and uses the platformResourceLoader to load the required resources (as below)
Promise.all([
loadStyle(this, communityDashboards + '/css/main.css'),
loadStyle(this, devExtreme + '/dx.common.css'),
loadStyle(this, devExtreme + '/dx.greenmist.css'),
loadScript(this, jquery341 + '/jquery-3.4.1.min.js'),
loadScript(this, devExtreme + '/dx.all.js')
])
.then(() => {
console.log('Successfully loaded Static Resources');
this.renderPie();
})
.catch(error => {
console.log('Error loading Static Resources');
console.log(JSON.stringify(error));
});
We've noticed the platformResourceLoader loads our resources multiple times rather than checking if the resource is already loaded. This appears to be a shift away from how Aura handled it, which was a one time load.
See below for the script/link tags that appear multiple times when 2 components are on the page, or when we navigate between pages that have components on them.
Does this look like a bug or shift in how LWC handles this? If it's intended, is there a recommended way of checking the resource is loaded? For the time being we are loading the resources in a single component (in our footer) as a work around.