Reputation: 7734
Currently, we're setting up dependencies inline on a html-page like this
<html>
<body>
<article>
Content
</article>
<script type="text/javascript">
define([
'View',
'Model'
], function(View, Model){
new View({ model: Model });
});
</script>
</body>
</html>
Almost every page where we do this has different dependencies. We stayed away from creating main.js files because it'd mean that we would have a main.js file for every one of these pages.
How would we best use the requirejs optimiser in our case?
Upvotes: 3
Views: 195
Reputation: 191
I've had much better success architecting my sites so that they share a common main.js. Or at least dividing the site into a small number sections that share builds. It takes some up-front planning, but it's a LOT easier to manage, and takes better advantage of the browser cache than one-build-per-page.
Upvotes: 1
Reputation: 115
You can't optimize inline scripts with require.js. You should take a look at htmlcompressor.
Having several main.js files is not a problem with require.js whatever you use anonymous modules or not.
Olivier
Upvotes: 0