Problems Very often when we updated the JS files, directly refreshing is not reflecting the changes, instead we need to manually clear cache, which makes end users using the web application quite annoying.
Solutions RequireJS provides "cache busting" which can force browser to download the latest version of JS files every time new pages loaded
Basically, we write a general function accepting target path not to cache, the "require.config" will then execute the function, the bust function actually use current time and attach as the parameter of the JS URL, since time is always changing, it can force the browser to retrieve the JS files for every load
This is official explanation /** * The function that handles definitions of modules. Differs from * require() in that a string for the module should be the first argument, * and the function to execute after dependencies are loaded should * return a value to define the module corresponding to the first argument's * name. */
jquery, bootstrap etc. is the self-defined name of js scripts to load, they are loaded in order
We must load the controller module for the AngularJS controller to work properly
Inside require function we have a second require function,which is called sugar function, it only loads the required modules for use inside the function, if you don't need it, you are NOT required to include in function parameters.
angular.bootstrap is to manually trigger the start of angularJS, which is highly recommended to use when cooperate with requireJS
When this was set, NO exists in the html view or AngularJS will throw errors
Normally, we will ignore the first parameter of the define function and let requireJS to use the file name as the module name (recommended)
Second array parameter tells requireJS that insiderApp module requires angular, angular-route and angular-animate to be loaded before executing the insiderApp module
function parameter "angular" is returned by the angular function, this object is for the implementation of insiderApp
Return the insiderApp variable or not depends on whether or not other modules need insiderApp, normally you need to return it.
var insiderApp = angular.module("insiderApp",["ngRoute", "ngAnimate"]); Just like usual, start the angular module, we can do any configuration of the angular object in this file.
controller.js
Just like usual, controller of the Angular object
define(['insiderApp'],function(insiderApp)...
Controller rely on insiderApp for adding controller to the Angular module, so we need to put insiderApp to the array and use it inside the function