Optimization with requirejs

We are currently installing inline dependencies on 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 didn't work on creating the main.js files because that would mean that we would have a main.js file for each of these pages.

How do we best use the requirejs optimizer in our case?

+3


source to share


2 answers


I have had much better success with the architecture of my sites so that they have a common main.js. Or at least dividing the site into small sections that separate assemblies. It does take some upfront planning, but it is much easier to manage and makes better use of the browser cache than a one-liner per page.



+1


source


You cannot optimize inline scripts with require.js. You should take a look at htmlcompressor .

Having multiple main.js files is not a problem with require.js, whether you are using anonymous modules or not.



Olivier salad

0


source







All Articles