django-requirejs

Allows you to organize imports of your js scripts
Download

django-requirejs Ranking & Summary

Advertisement

  • Rating:
  • License:
  • BSD License
  • Price:
  • FREE
  • Publisher Name:
  • Max Syabro
  • Publisher web site:
  • https://github.com/syabro/

django-requirejs Tags


django-requirejs Description

Based on Sam Stephenson's sprockets django-requirejs allows you to organize imports of your js scripts.UsageF.e. you have 3 scripts- script.js- dep1.js- dep2.jsSecond two are necessery to run code in script.js. Without RequireJS you'll use something in your html:< head > ... < script src="{{ STATIC_URL }}dep2.js" type="text/javascript" >< /script > < script src="{{ STATIC_URL }}dep1.js" type="text/javascript" >< /script > < script src="{{ STATIC_URL }}script.js" type="text/javascript" >< /script >Looks simple enough. But what's going on when you have 30 files with cross-depencies? You have two ways: 1. To import all to be sure that all required libs are loaded. 2. To import only needed scripts, paying that everything will be okRequireJS makes it simple ass possible. 1. Lets include dep1.js and dep2.js in script.js.//= include dep1.js//= include dep2.js Include script.js in your html ... //= include script.js Show place where imported files should be. In our case it's in head< head > ... < !-- INCLUDE_JS_HERE -- > < script type="text/javascript" > //= include script.js < /script >Loader will convert it to< head > ... < script src="{{ STATIC_URL }}dep2.js" type="text/javascript" > < script src="{{ STATIC_URL }}dep1.js" type="text/javascript" > < script src="{{ STATIC_URL }}script.js" type="text/javascript" > ...Installation1. Install library2. Enable "requirejs" in your INSTALLED_APPS3. Add "requirejs.templateloader.filesystem.Loader" to your TEMPLATE_LOADERSIncluding librariesIn javascript: //= include jquery.jsProduct's homepage


django-requirejs Related Software