0

Is there a way to have a main script that act like a "global" script for all pages of a site while still have specific page script when using requiere.js.

This would be called on all pages

<script data-main="resources/js/main" src="resources/js/libs/require.js"></script>

and on other page i would like to add other dependencies without having to create a different main.js script.

Is there any way to do so ?

EDIT: Just found a way that seems to be working pretty well so far:

<script> require.config({ deps : ['register'] }) </script>

Any other ideas?

silkAdmin
  • 4,640
  • 10
  • 52
  • 83

1 Answers1

1

You can implement a global main and a page main scripts, something like this (the data-start is not part of the requirejs, is hand-made as described on the link below):

<script data-main="globalmain.js" data-start="page/main" src="require.js"/>

More details here: How to use RequireJS build profile + r.js in a multi-page project

Community
  • 1
  • 1
Marcelo De Zen
  • 9,439
  • 3
  • 37
  • 50
  • That's pretty net, thanks for the link. How ever i found that https://github.com/requirejs/example-multipage, is probably an approach that stick closer to the requireJS way – silkAdmin Aug 30 '12 at 11:26
  • @silkAdmin, is a very good boilerplate for requirejs, for me is a little verbose though. Good luck ;) – Marcelo De Zen Aug 30 '12 at 23:08