Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Optimising with requirejs

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?

like image 616
Julian Krispel-Samsel Avatar asked Apr 17 '26 21:04

Julian Krispel-Samsel


1 Answers

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.

like image 104
shovemedia Avatar answered Apr 20 '26 11:04

shovemedia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!