Question

In the app working with, I don't have a way of specyfing attributes on the tag for requirejs. I can specify the script tag in the form of

<script type="text/javascript" src="scripts/require.js"></script>

I can append another tag before or after this one and include code to bootstrap my app (main module). I am using jQuery 1.7.1 and would like to load it as dependency in other modules. I also want to do that without the requirejs-jquery bundle, so jQuery seperate of requirejs. I am looking for the right way to do that. I am fairly new to requirejs so an explanation of how the modules are loaded and a code sample would be great. Thanks!

Was it helpful?

Solution

include another javascript file after requirejs.

<script type="text/javascript" src="scripts/require.js"></script>
<script type="text/javascript" src="scripts/main.js"></script>

In this file you have to configure requirejs so it finds jquery.

main.js

require.config({
    paths: {
        "jquery": "js/jquery-1.7.1.min"//edit this path so it suits your needs.
  } 
});

From now on you'll be able to load jquery into your Modules by

require(['jquery'], function ($) {
    $('#foo').show();
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top