3 ms·
javascript "module" dependencies are written in javascript, not in html renderer. in development: <script data-main="your-module.js" src="require.js"></sc
by the1 13y ago
javascript "module" dependencies are written in javascript, not in html renderer.
in development:
<script data-main="your-module.js" src="require.js"></script>
in production:
<script src="your-module.min.js"></script>
One problem I haven't solved is when html renderer writes inputs to your javascript module. I can either print my module's main body in html:
<script>
require(['yourModule'], function(yourModule) {
var config = {% server template vars %};
yourModule.start(config);
});
</script>
Or use global config variable and shim.
- Davertron 13y agoYeah, I've run into this as well. I would say avoid doing this if you can and use an AJAX call from inside the javascript to pull the data in that you need. Sometimes this isn't feasible/ideal though (especially if the data is slow to get/calculate and is already used on the html page...). If you can cache the results of the calculation on the server-side, that would mitigate the performance implications a bit and then you just have the overhead of the request itself.