Modules.Register Options

  •  

Updating Nercon's snippets on 6.9.5 upgrade to leverage Modules.Register.

Snippets before (these were in Pre-Titan Snippets area):

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="/CommonScripts/NWS.js"></script>
<link type='text/css' rel='stylesheet' href='/ClientCss/lightboxv2.css'>
<script src="/CommonScripts/lightbox.min.js"></script>
<script language="JavaScript" type="text/javascript" src="/CommonScripts/NerconResponsive.js"></script>

  1. Remove NWS.js because it is now part of titanscripts.required.js and move any snippets that are dependent on it to the Post-Titan Snippets.
  2. Update snippets to just call one file which handles the rest.
<script language="JavaScript" type="text/javascript" src="/CommonScripts/Nercon_site.js"></script>

Inside that file:

// preloaded and deferred CSS files that are not needed for immediate above the fold content
var CSSBundleModules = ["/ClientCss/lightboxv2.css"];
NWS.Modules.Register(CSSBundleModules,null,"preload");

//load jQuery and then anything that is dependent on jQuery - ordering of files matters
var firstModules = [
new NWS.Bundling.Resource("//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js", new NWS.Bundling.Callback(function() { 
		NWS.Modules.Register([			
			// Third-party JS files
			"/CommonScripts/lightbox.min.js", 
			"/CommonScripts/matchHeight.js", 
			"/CommonScripts/fitVids.js",
			
			// Custom JS files
			"/CommonScripts/NerconResponsive.js"
		]) }))
];

var firstModulesInit = function() {
		// load the deferred CSS
		$(window).on("load", function() {
			 NWS.Modules.Register(CSSBundleModules);
		});
};
NWS.Modules.Register(firstModules, firstModulesInit);

A couple things:

  • FitVids and matchHeight were in the NerconResponsive.js file (our old manual method of bundling), and they were not coming in the right order. So, I separated them out into their own files and added them to the queue.
  • Because firstModulesInit is called on document.ready. I had to put the whole Modules.Register code into a separate file to make sure all the files were available before the document.ready function inside the NerconResponsive.js file runs.
© 2017 Northwoods - all rights reserved.
top