Ce document décrit une configuration de requirejs,un chargeur de modules javascript. Il s’agit essentiellement d’une carte indiquant à requirejs où trouver les modules et comment ils sont liés les uns aux autres.
paths: C’est la partie la plus importante. Elle définit des alias pour les noms de modules et leurs chemins de fichiers correspondants.
Des exemples d’alias incluent :
"facebook": "https://connect.facebook.net/en_US/sdk.js": Alias pour le SDK Facebook."google": "https://apis.google.com/js/plusone.js": Alias pour Google Plus One."gpt": "https://securepubads.g.doubleclick.net/tag/js/gpt.js": alias pour Google Publisher tag."hlsjs": "https://cdnjs.cloudflare.com/ajax/libs/hls.js/1.0.7/hls.js": Alias pour HLS.js."video-avia": "https://sports.cbsimg.net/fly/js/avia-js/2.48.0/player/avia.min.js": Alias pour un lecteur vidéo.
Il existe de nombreux autres alias définis pour divers scripts externes.
waitSeconds: Cela définit le délai d’attente (en secondes) pour le chargement des modules.Si un module ne se charge pas dans les 300 secondes, RequireJS générera une erreur.
Plugin version!
On remarque le préfixe version! dans certaines dépendances (par exemple, "version!fly/libs/underscore"). Il s’agit d’un plugin RequireJS utilisé pour forcer la mise en cache des modules.
Okay, this looks like a RequireJS configuration. Let’s break down what it means.
Overall structure
This is a JavaScript object that defines how the RequireJS module loader should handle dependencies and load scripts. It’s essentially a map telling RequireJS where to find modules and how they relate to each other.
Key Sections
-
paths: This is the most vital part. It defines aliases for module names and their corresponding file paths.
"underscore-1.5.1": {"exports": ""},: This means that the module named "underscore-1.5.1" can be loaded, and when it’s loaded, it will export its contents as the variable (which is the standard way to access Underscore.js). The exports property tells RequireJS what variable the module makes available globally. "fly/libs/backbone-1.0.0": {"deps": ["version!fly/libs/underscore", "jquery"], "exports": "Backbone"},: This defines the backbone-1.0.0 module.
deps: This array lists the dependencies that backbone-1.0.0 requires.It needs fly/libs/underscore (specifically, the versioned version of it) and jquery.
exports: This indicates that the module exports its contents as the variable Backbone.
"libs/jquery/ui/jquery.ui.tabs-1.11.4": ["jquery", "version!libs/jquery/ui/jquery.ui.core", "version!fly/libs/jquery.widget"],: This defines the jquery.ui.tabs-1.11.4 module. It depends on jquery,the core jQuery UI module (jquery.ui.core), and a jQuery widget library.
"libs/jquery/flexslider-2.1": ["jquery"],: the flexslider-2.1 module depends on jQuery.
"libs/dataTables.fixedColumns-3.0.4": ["jquery", "version!libs/dataTables"],: The dataTables.fixedColumns-3.0.4 module depends on jQuery and the dataTables module (versioned).
"libs/dataTables.fixedHeader-2.1.2": ["jquery", "version!libs/dataTables"],: The dataTables.fixedHeader-2.1.2 module depends on jQuery and the dataTables module (versioned).
"https://sports.cbsimg.net/js/CBSi/app/VideoPlayer/AdobePass-min.js": ["https://sports.cbsimg.net/js/CBSi/util/Utils-min.js"]: This module depends on another external script.
-
map: This section defines aliases for external URLs. It’s used to provide shorter, more manageable names for commonly used libraries.
"": { ... }: The "" means these aliases apply globally (to all modules).
"adobe-pass": "https://sports.cbsimg.net/js/CBSi/app/VideoPlayer/AdobePass-min.js",: Instead of writing the full URL for Adobe Pass,you can just use "adobe-pass" in your require() calls.
"facebook": "https://connect.facebook.net/en_US/sdk.js",: Alias for the Facebook SDK.
"google": "https://apis.google.com/js/plusone.js",: Alias for Google Plus One.
"gpt": "https://securepubads.g.doubleclick.net/tag/js/gpt.js",: Alias for Google Publisher Tag.
"hlsjs": "https://cdnjs.cloudflare.com/ajax/libs/hls.js/1.0.7/hls.js",: Alias for HLS.js.
"video-avia": "https://sports.cbsimg.net/fly/js/avia-js/2.48.0/player/avia.min.js",: Alias for a video player.
* And so on… There are many more aliases defined for various external scripts.
-
waitSeconds: This sets the timeout (in seconds) for loading modules. if a module doesn’t load within 300 seconds, RequireJS will throw an error.
version! Plugin
you’ll notice the version! prefix in some dependencies (e.g., "version!fly/libs/underscore"). This is a RequireJS plugin that’s used to bust the cache for
