1

i'm new with Require.js and need some help (trust me, i search a lot but still lost).

In my development environment, i need to prevent require to cache the files. Ok, i already searched around and found this solution Prevent RequireJS from Caching Required Scripts

But when i put it in my require.config code, i lost all my references from jQuery, etc...
The error i get is:

Uncaught TypeError: undefined is not a function 
Uncaught ReferenceError: jQuery is not defined 

I think something is wrong with my code, but don't know what (dependencies, references...).

In the main.js:

requirejs.config({
 "urlArgs": "bust=" + (new Date()).getTime()
 "baseUrl": "js/app",
 "paths": {
    "doctorWorklist": "doctor-worklist",
    "jquery": "//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min",
    "bootstrap": "../lib/bootstrap.min",
    "app": "app"
 }
});

// Load the main app module to start the app
requirejs(["app"]);

In the app.js

define( ['jquery', 'bootstrap'], function( $ ) {
 //my code here.
});

Any suggestions ?
And sorry about the bad english. :D

-- Update September, 18. I got it ! For those who are beginning with require.js like me, the error related above was in main.js

For my purpose, the code of main.js must be like:

requirejs.config({
"urlArgs": "bust=" + Math.random(),
"baseUrl": "js/app",
"paths": {
    "doctorWorklist": "doctor-worklist",
    "jquery": "//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min",
    "dataTables": "http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min",
    "bootstrap": "../lib/bootstrap.min",
    "bootstrapDatepicker": "../lib/bootstrap-datepicker.min",
    "bootstrapSelect": "../lib/bootstrap-select.min",
    "jPlayer": "../lib/jquery.jplayer.min",
    "countdown": "../lib/jquery.countdown.min",
    "countdownBR": "../lib/jquery.countdown-pt-BR.min",
    "googleapi": "../lib/googlecharts-api",
    "onrad": "onrad"
}
});

// Load the main app module to start the app
requirejs(["jquery"], 
function($, jQuery) {
    var jQuery = $;
    // This moment, jQuery is completely loaded.
    // Time to require external libs with jQuery dependencies
    requirejs(
        [
            "dataTables",
            "bootstrap", 
            "bootstrapDatepicker", 
            "bootstrapSelect"                
        ]
    , function($, jQuery) {
        // External libs loaded !
        // Time to required my app code
        requirejs(["countdown", "countdownBR", "onrad"]);
    });
}
);

Hope it be useful for someone.

Community
  • 1
  • 1
victorkurauchi
  • 1,390
  • 18
  • 23

0 Answers0