You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Just thinking out loud, I haven't done any testing or research on this yet. Feel free to close this issue if you see no merit.
It would be nice to make sure that a script isn't loaded more than once. I'm thinking this could be done by checking the DOM to see if any of the existing script tags has the same src as the script that is about to be loaded.
I'm currently using feature detection to avoid loading modules multiple times. This works for things like jquery, underscore, backbone, etc. This means I'm wrapping code around each $script call. And feature detection wouldn't really work for scripts that don't add some property to an object within the window tree.
My use case is different than most who are building standard web pages. I'm creating widgets that can be installed anywhere. Many of the widgets I'm building have the same dependencies and load several additional libraries (jquery, underscore, backbone, etc.). So it would be very easy to load the same resources multiple times when multiple widgets are placed on a page.
Bottom line is that if more than one widget is placed on the same page, I'd like to make sure they both don't load the same resources. Perhaps feature detection is the best solution. But maybe it makes sense for the loader to simply check if the src is already in the DOM.
Also, if my pull request to add $script.styles is incorporated, it would be nice to have a way that stylesheets aren't loaded more than once as well. That is much harder to detect with feature detection.
The text was updated successfully, but these errors were encountered:
well, if you're using this utility to load all your js assets, then it already checks if you've previously loaded the same asset based on path. See here
eg:
// begin fetching bar.js$script('/foo/bar.js',function(){})// bar.js is not loaded, but will receive callback$script('/foo/bar.js',function(){})
Just thinking out loud, I haven't done any testing or research on this yet. Feel free to close this issue if you see no merit.
It would be nice to make sure that a script isn't loaded more than once. I'm thinking this could be done by checking the DOM to see if any of the existing script tags has the same
src
as the script that is about to be loaded.I'm currently using feature detection to avoid loading modules multiple times. This works for things like jquery, underscore, backbone, etc. This means I'm wrapping code around each
$script
call. And feature detection wouldn't really work for scripts that don't add some property to an object within thewindow
tree.My use case is different than most who are building standard web pages. I'm creating widgets that can be installed anywhere. Many of the widgets I'm building have the same dependencies and load several additional libraries (jquery, underscore, backbone, etc.). So it would be very easy to load the same resources multiple times when multiple widgets are placed on a page.
Bottom line is that if more than one widget is placed on the same page, I'd like to make sure they both don't load the same resources. Perhaps feature detection is the best solution. But maybe it makes sense for the loader to simply check if the
src
is already in the DOM.Also, if my pull request to add $script.styles is incorporated, it would be nice to have a way that stylesheets aren't loaded more than once as well. That is much harder to detect with feature detection.
The text was updated successfully, but these errors were encountered: