Check if an AMD module exists and load fallback otherwise
Author: jslegersCreated May 18, 2018Updated Sep 22, 2024
What I'm trying to achieve is this :
- I want to check if module
namespace/Ais available on the server - If it is available, I want to load
namespace/A - If it is not available, I want to load
namespace/Bas a fallback
Now...
- For non-bundled modules, I could use an Ajax call to check for the availability of
path/to/A. - For bundled modules, I could use
require.specified()to check ifnamespace/Ahas been specified already. - I guess I could first use
require.specified()and then use an Ajax call if I want to support both non-bundled and bundled modules... but I can't really say I like this approach.
Is there a simpler way to conditionally load namespace/A if namespace/A is available and fall back to namespace/B otherwise, using require.js?
Source: requirejs/requirejs