I think I need to support multiple instances of the request on the page, and I am facing two problems that are causing this to happen. I am working on a service that delivers embedded interactive objects to external client pages. The best design criteria are easily integrated, making as little assumptions about the client environment as possible and playing perfectly in the js / css world of the client page. Clients add a script tag to their page to load the bootloader, and then they use the built-in script to load the content they want:
<script src="http://server.net/loader"></script> <script> special_require(["loader"], function(loader) { loader.load({ object: "objectname", target: "#where-i-want-it" </script>
The loader launches the require.js source in an anonymous function, configures it, and then requires export and defines it as global variables with names (call them special_require and special_define). Then a few special_defined modules, ending with a โbootloaderโ:
// Using strategy 2 from http://requirejs.org/docs/faq-advanced.html#rename to // namespace require so it doesn't conflict with code on client sites. ;(function() { // Here, we use Jinja to drop in require.js, which will define itself in // this non-global namespace. {% include 'loader/require.js' %} require.config({ ... }) window.special_require = require window.special_define = define })() special_define("loader", [...], function(...) { ... })
For the most part this works very well. I can completely abandon any requirements required on the client page, and I easily go through the global js client namespace. But:
If a necessity is loaded on the client page and called with the data-main attribute, I need to show and try to load the main script for my baseUrl, and we will get a loading error. I can change the source of my request so that it does not look for the data-main attribute. Is there a cleaner solution?
The requirement of the community is very clear that the page should not have more than one instance of the request. The require.js source goes out of its way to avoid duplication. So I'm nervous that I'm tuning in to troubles along the line, following this path. However, I'm even more nervous about the possible use of the require client instance (with my own loading context). Require 1,2, 2.0 and 2.1 are incompatible, and I do not know what I worked with. Am I just in an unusual situation when it makes sense to have a separate mode of operation? Am I heading for trouble? Is there a way to load require.js and allow it to be deferred to an existing requirement when possible, while still having some confidence that I have a specific version?
cproctor
source share