9 Django packages that help manage the static assets of a project

A faster collectstatic command.

Make sure you have this in your settings file and add 'collectfast' to your INSTALLED_APPS, before 'django.contrib.staticfiles':

STATICFILES_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
COLLECTFAST_STRATEGY = "collectfast.strategies.boto3.Boto3Strategy"
INSTALLED_APPS = (
    # ...
    "collectfast",
)
assets-management django performance python

 

Compresses linked and inline javascript or CSS into a single cached file.

 

Django-gears/

Django-gears - Python

54

Gears for Django.

 

Django-htmlmin/

Django-htmlmin - Python

514

HTML minifier for Python frameworks (not only Django, despite the name).

All you need to do is add two middlewares to your MIDDLEWARE_CLASSES and enable the HTML_MINIFY setting:

MIDDLEWARE_CLASSES = (
    # other middleware classes
    'htmlmin.middleware.HtmlMinifyMiddleware',
    'htmlmin.middleware.MarkRequestMiddleware',
)

 

 

Django-pipeline

Django-pipeline - Python

1.4k

Pipeline is an asset packaging library for Django.

 

Django SystemJS brings the JavaScript of tomorrow to Django, today. (JSPM integration in Django)

 

Django-webpack-loader

Django-webpack-loader - Python

2.4k

Transparently use webpack with django

Before configuring django-webpack-loader, let's first configure what's necessary on webpack-bundle-tracker side. Update your Webpack configuration file (it's usually on webpack.config.js in the project root). Make sure your file looks like this (adapt to your needs):

const path = require('path');
const webpack = require('webpack');
const BundleTracker = require('webpack-bundle-tracker');

module.exports = {
  context: __dirname,
  entry: './assets/js/index',
  output: {
    path: path.resolve('./assets/webpack_bundles/'),
    filename: "[name]-[hash].js"
  },
  plugins: [
    new BundleTracker({filename: './webpack-stats.json'})
  ],
}
assets django django-webpack-loader javascript reactjs static webpack

 

Python bindings to webpack

If you are already using config files which export an object, wrap the generation of the object in a function. For example:

// if you currently have
module.exports = {
  // ...
};

// rewrite it as
module.exports = function() {
  return {
    // ...
  };
};

 

A django compressor tool that bundles css, js files to a single css, js file with webpack and updates your html files with respective css, js file path.

pip install django-webpacker

            (or)

git clone git://github.com/micropyramid/django-webpacker.git

cd django-webpacker

python setup.py install
compressor css-js django package pip webpack