Python CSS/Javascript minifier

Related tags

DjangoSqueezeit
Overview

Squeezeit - Python CSS and Javascript minifier Copyright (C) 2011 Sam Rudge

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

#WTF? Squeezeit is a small Python utility to scratch my own personal itch. It attempts to provide a lot of the features of the Rails asset pipeline with regards to combining and minifying bundles of Javascript and CSS files, pre-compressing .gz versions of files and simplifying management of site media.

#Make shit happen Download, setup.py install and run squeezeit /path/to/config.yaml (see below)

#Configuration Squeezeit is configured through the use of YAML files. There are two types of YAML file needed for squeezeit to run;

##Main config.yaml Specifies the main configuration options for the bundler, such as source directories and output directories.

#Main bundle config
#All paths are relative to this file

#Logging level (Standard Python logging levels: DEBUG, INFO, WARNING or CRITICAL)
logging: INFO

#Specify the directory for bundle YAML files (The files that specify your bundles and their contents)
bundles: ./config/

#Where to output the bundles and bundle info file
output: ./bundles/

#Source files
css: ./css/
javascript: ./js/

#Bundle names include MD5 hash of contents (E.G. [bundlename]-[md5 hash].js - See bundle info file)
hashfilenames: true

##Bundle configuration files These are YAML files in the 'bundles' directory specified above. A bundle config file contains all the media that should be included with a particular bundle. Output bundles will be named the same as the YAML file (so media.yaml will output media.js, media.css etc.)

#Paths are relative to the 'source file' directories specified in the main config file
includes:
    css:
        - clear.css
        - fonts.css
        - bootstrap.css
		- main.css
    javascript:
        - jquery/core.js #Oh, you can use sub-folders too
        - main.js

All bundles will output 6 (or 3) files;

  • bundlename.js/css - Combined but not minified files, this is the same as cat file1.js file2.js >> bundle.js
  • bundlename.min.js/css - Combined and minified versions of the files. JS minification is done using JSMin and CSS minification is done using slimmer
  • bundlename.min.js/css.gz - Combined, minified and GZipped version of the file.

You don't have to include both javascript and CSS in a bundle, just leave the array blank in the bundle config file

##Bundle info file The bundler outputs a 'bundle info file' to output-directory/info.yaml. The bundle info file contains information about the sizes of the bundles, and their MD5 has (useful for using MD5 in filenames).

media:
	css:
		md5: 3c716f5993efd3257fe17b219c6b6ecd #MD5 is generated from the combined data, before it's minified
		output: {
			gz: media-3c716f5993efd3257fe17b219c6b6ecd.min.css.gz,
			min: media-3c716f5993efd3257fe17b219c6b6ecd.min.css,
			raw: media-3c716f5993efd3257fe17b219c6b6ecd.css
		}
		size: {
			gz: 328,
			min: 704,
			raw: 821
		}
	javascript:
		md5: 9581d699b54badf07d4e1f60f77dca7d
		output: {
			gz: media-9581d699b54badf07d4e1f60f77dca7d.min.js.gz,
			min: media-9581d699b54badf07d4e1f60f77dca7d.min.js,
			raw: media-9581d699b54badf07d4e1f60f77dca7d.js
		}
		size: {
			gz: 33142,
			min: 93837,
			raw: 93939
		}

If ether Javascript or CSS source files are not specified in the bundle, the value of 'md5' will be set to false (md5: false) so you can detect that from your code.

#It wasn't all me

Squeezeit includes two excellent libraries to do it's work (on top of the standard Python ones);

  • JSMin.py - By Douglas Crockford and Dave St.Germain
  • Slimmer - By Peter Bengtsson

Other cool things to check out;

  • PNGCrush - Great at optimising images and stuff
Owner
Smudge
Coding dog thing. I make servers do stuff, not always the stuff they want to do.
Smudge
Source files for a free pyRevit toolbar.

pyRoovit (WIP) What is this? PyRoovit is/will be a toolbar for the use with pyRevit built by Gavin Crump (aka Aussie BIM Guru). Having used and taught

Gavin Crump 11 Nov 10, 2022
Modular search for Django

Haystack author: Daniel Lindsley date: 2013/07/28 Haystack provides modular search for Django. It features a unified, familiar API that allows you to

Daniel Lindsley 4 Dec 23, 2022
The pytest framework makes it easy to write small tests, yet scales to support complex functional testing

The pytest framework makes it easy to write small tests, yet scales to support complex functional testing for applications and libraries. An example o

pytest-dev 9.6k Jan 06, 2023
This is a Django app that uses numerous Google APIs such as reCAPTURE, maps and waypoints

Django project that uses Googles APIs to auto populate fields, display maps and routes for multiple waypoints

Bobby Stearman 57 Dec 03, 2022
Mobile Detect is a lightweight Python package for detecting mobile devices (including tablets).

Django Mobile Detector Mobile Detect is a lightweight Python package for detecting mobile devices (including tablets). It uses the User-Agent string c

Botir 6 Aug 31, 2022
GameStop clone with Django

GameStop clone with Django This is my side project with GameStop clone Author: HackerApe GitHub Profile: View Profile LinkedIn Profile: View Profile

Dmitriy Shin 2 Dec 26, 2021
A app for managing lessons with Django

Course Notes A app for managing lessons with Django Some Ideas

Motahhar.Mokfi 6 Jan 28, 2022
English dictionary using Django based on freecodecamp

English Dictionary Hi there, i made this english dictionary using Django based on freecodecamp.org tutorial :) Table of Contents Preview Technologies

Aline Alencar 3 May 09, 2022
Declarative model lifecycle hooks, an alternative to Signals.

Django Lifecycle Hooks This project provides a @hook decorator as well as a base model and mixin to add lifecycle hooks to your Django models. Django'

Robert Singer 1k Dec 31, 2022
A task management system created using Django 4.0 and Python 3.8 for a hackathon.

Task Management System A task management app for Projects created using Django v4.0 and Python 3.8 for educational purpose. This project was created d

Harsh Agarwal 1 Dec 12, 2021
Django React - Purity Dashboard (Open-Source) | AppSeed

Django React Purity Dashboard Start your Development with an Innovative Admin Template for Chakra UI and React. Purity UI Dashboard is built with over

App Generator 19 Sep 19, 2022
Tweak the form field rendering in templates, not in python-level form definitions. CSS classes and HTML attributes can be altered.

django-widget-tweaks Tweak the form field rendering in templates, not in python-level form definitions. Altering CSS classes and HTML attributes is su

Jazzband 1.8k Jan 02, 2023
An orgizational tool to keep track of tasks/projects and the time spent on them.

Django-Task-Manager Task Tracker using Python Django About The Project This project is an orgizational tool to keep track of tasks/projects and the ti

Nick Newton 1 Dec 21, 2021
Store events and publish to Kafka

Create an event from Django ORM object model, store the event into the database and also publish it into Kafka cluster.

Diag 6 Nov 30, 2022
A Django GraphQL (Graphene) base template

backend A Django GraphQL (Graphene) base template Make sure your IDE/Editor has Black and EditorConfig plugins installed; and configure it lint file a

Reckonsys 4 May 25, 2022
Add a help desk or knowledge base to your Django project with only a few lines of boilerplate code.

This project is no longer maintained. If you are interested in taking over the project, email Zapier 487 Dec 06, 2022

Django Girls Tutorial Workshop

Django Girls Tutorial Workshop A log of activities during the workshop. this is an H2 git remote add origin https://github.com/ahuimanu/django_girls_t

Jeffry Babb 1 Oct 27, 2021
Packs a bunch of smaller CSS files together from 1 folder.

Packs a bunch of smaller CSS files together from 1 folder.

1 Dec 09, 2021
Django backend of Helium's planner application

Helium Platform Project Prerequisites Python (= 3.6) Pip (= 9.0) MySQL (= 5.7) Redis (= 3.2) Getting Started The Platform is developed using Pytho

Helium Edu 17 Dec 14, 2022
REST API con Python, Django y MySQL (GET, POST, PUT, DELETE)

django_api_mysql REST API con Python, Django y MySQL (GET, POST, PUT, DELETE) REST API con Python, Django y MySQL (GET, POST, PUT, DELETE)

Andrew 1 Dec 28, 2021