admin管理员组

文章数量:1406943

What is the simplest way to bine JavaScript files into a single file in a Django project?

Explanation

I want this to work with Ember.js/Backbone where you (usually) have many different JavaScript in multiple directories. Directories would all be in one folder called app/ for example, like: app/views/ app/models/ /app/routers/

Requirements

  • Work together with the staticfiles app
  • Still be separated while in development mode for easier debugging (only pile when calling collectstatic?)
  • Work with Require.js (guess that shouldn't be too hard, but putting it in here to be sure)

Extra credit

Explain a best practices way of bining Django and Ember/Backbone.

What is the simplest way to bine JavaScript files into a single file in a Django project?

Explanation

I want this to work with Ember.js/Backbone where you (usually) have many different JavaScript in multiple directories. Directories would all be in one folder called app/ for example, like: app/views/ app/models/ /app/routers/

Requirements

  • Work together with the staticfiles app
  • Still be separated while in development mode for easier debugging (only pile when calling collectstatic?)
  • Work with Require.js (guess that shouldn't be too hard, but putting it in here to be sure)

Extra credit

Explain a best practices way of bining Django and Ember/Backbone.

Share Improve this question edited Dec 15, 2011 at 23:51 Yehuda Katz 28.7k12 gold badges90 silver badges92 bronze badges asked Dec 15, 2011 at 19:49 c4urselfc4urself 4,28722 silver badges34 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

I am an happy user of django pressor, it does bine, minify, debug-friendly, you can use it with staticfiles, easy to plug with custom storage backend (eg. S3)

https://github./jezdez/django_pressor

The reason you want to bine many files into one is so to minimize latency of setting up and tearing down http requests, the fewer you make the better. However, many newer browsers are downloading JavaScript files in parallel (still executing sequentially). The consequence is that downloading a single 1Mb file may be slower than three 350Kb files.

you can use from CDNs.

As mentioned in the previous answer, django-pressor is nice, but you often get better loading times when using a dedicated javascript loader instead. My tip is to check out Head.js for example (http://headjs./) (there are tons other out there as well). Often bining scripts can be contra productive when considering caching, using javascript located on CDN:s etc.

One thing to remember is that Iphone 3/4 will just cache 15/25KB of javascript, so if you have huge scripts and bine them you can run into trouble. http://www.phpied./iphone-caching/

本文标签: Combining and Compressing multiple JavaScript files into a single file in a Django projectStack Overflow