Python CSS/Javascript minifier

Related tags

Django Squeezeit
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
Comments
  • Added semicolons in JS concatenation

    Added semicolons in JS concatenation

    I kept on running into issues with JS files that do not end with a trailing semicolon followed by files that begin with an open parenthesis.

    To resolve this within Squeezeit I've removed the concatenation from the generic load function and added it to the JS/CSS specific code. This means the load function now returns a list containing the loaded file contents rather than a single concatenated string.

    There is probably a better way to do this, but this at least prevents concatenation-induced syntax errors.

    opened by pluma 1
  • Should preserve IE conditional compilation comments in the minified versions

    Should preserve IE conditional compilation comments in the minified versions

    Current implementation of minifying removes all comments. However comments like /@cc_on @/,/@if ... @/ should be preserved so conditional compilation functionality in IE is preserved.

    opened by gamooga 1
  • maybe we could work togather do you know PHP?

    maybe we could work togather do you know PHP?

    I am working on a very cool proxy script that uses PHP + CURL, MySQL (for user database if more one user) you are working on a very good project maybe could you help make my project and intergrate your project with mine togather we can be great and your product could become huge

    opened by ghost 1
  • Added directory/wildcard support

    Added directory/wildcard support

    I've added support for directories with an optional file suffix. In other words the following paths are now supported:

    - /foo/bar
    - /foo/bar/*.js
    

    In the first case if bar is a dir, all files in bar and its subfolders will be loaded. In the second case only the files ending in ".js" will be added.

    It's a bit incomplete in that there's no way to add only files directly contained in the folder itself (and not its subfolders) and the wildcard doesn't allow prefixes. I would have used glob, except I can't find a way to make glob also search in subfolders and I favoured the more inclusive approach because this was born out of the need of having deep hierarchies of JS files that I don't want to have to keep track of in Squeezeit.

    opened by pluma 0
  • Output directory isn't created

    Output directory isn't created

    If the output directory bundles/ doesn't exist, I get the error

    CRITICAL:root:Could not write file [workingdir]/bundles/styles.css
    

    But If I touch ./bundles/styles.css before running the Squeezeit command, everything works.

    (I don't mind doing this workaround, but I thought this deserved submitting an issue.)

    opened by menzenski 0
Owner
Smudge
Coding dog thing. I make servers do stuff, not always the stuff they want to do.
Smudge
Compresses linked and inline javascript or CSS into a single cached file.

Django Compressor Django Compressor processes, combines and minifies linked and inline Javascript or CSS in a Django template into cacheable static fi

null 2.6k Jan 3, 2023
Fully reponsive Chat Application built with django, javascript, materialUi, bootstrap4, html and css.

Chat app (Full Stack Frameworks with Django Project) Fully reponsive Chat Application built with django, javascript, materialUi, bootstrap4, html and

null 1 Jan 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 2, 2023
Basic Form Web Development using Python, Django and CSS

thebookrain Basic Form Web Development using Python, Django and CSS This is a basic project that contains two forms - borrow and donate. The form data

Ananya Dhulipala 1 Nov 27, 2021
This "I P L Team Project" is developed by Prasanta Kumar Mohanty using Python with Django web framework, HTML & CSS.

I-P-L-Team-Project This "I P L Team Project" is developed by Prasanta Kumar Mohanty using Python with Django web framework, HTML & CSS. Screenshots HO

null 1 Dec 15, 2021
Packs a bunch of smaller CSS files together from 1 folder.

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

null 1 Dec 9, 2021
Simple alternative to Doodle polls and scheduling (Python 3, Django 3, JavaScript)

What is jawanndenn? jawanndenn is a simple web application to schedule meetings and run polls, a libre alternative to Doodle. It is using the followin

Sebastian Pipping 169 Jan 6, 2023
A django model and form field for normalised phone numbers using python-phonenumbers

django-phonenumber-field A Django library which interfaces with python-phonenumbers to validate, pretty print and convert phone numbers. python-phonen

Stefan Foulis 1.3k Dec 31, 2022
Stream Framework is a Python library, which allows you to build news feed, activity streams and notification systems using Cassandra and/or Redis. The authors of Stream-Framework also provide a cloud service for feed technology:

Stream Framework Activity Streams & Newsfeeds Stream Framework is a Python library which allows you to build activity streams & newsfeeds using Cassan

Thierry Schellenbach 4.7k Jan 2, 2023
Learn Python and the Django Framework by building a e-commerce website

The Django-Ecommerce is an open-source project initiative and tutorial series built with Python and the Django Framework.

Very Academy 275 Jan 8, 2023
Build reusable components in Django without writing a single line of Python.

Build reusable components in Django without writing a single line of Python. {% #quote %} {% quote_photo src="/project-hail-mary.jpg" %} {% #quot

Mitchel Cabuloy 277 Jan 2, 2023
Sampling profiler for Python programs

py-spy: Sampling profiler for Python programs py-spy is a sampling profiler for Python programs. It lets you visualize what your Python program is spe

Ben Frederickson 9.5k Jan 1, 2023
A django model and form field for normalised phone numbers using python-phonenumbers

django-phonenumber-field A Django library which interfaces with python-phonenumbers to validate, pretty print and convert phone numbers. python-phonen

Stefan Foulis 1.3k Dec 31, 2022
Python port of Google's libphonenumber

phonenumbers Python Library This is a Python port of Google's libphonenumber library It supports Python 2.5-2.7 and Python 3.x (in the same codebase,

David Drysdale 3.1k Jan 8, 2023
The uncompromising Python code formatter

The Uncompromising Code Formatter “Any color you like.” Black is the uncompromising Python code formatter. By using it, you agree to cede control over

Python Software Foundation 30.7k Jan 3, 2023
Code coverage measurement for Python

Coverage.py Code coverage testing for Python. Coverage.py measures code coverage, typically during test execution. It uses the code analysis tools and

Ned Batchelder 2.3k Jan 5, 2023
Faker is a Python package that generates fake data for you.

Faker is a Python package that generates fake data for you. Whether you need to bootstrap your database, create good-looking XML documents, fill-in yo

Daniele Faraglia 15.2k Jan 1, 2023
a little task queue for python

a lightweight alternative. huey is: a task queue (2019-04-01: version 2.0 released) written in python (2.7+, 3.4+) clean and simple API redis, sqlite,

Charles Leifer 4.3k Dec 29, 2022
Auto-detecting the n+1 queries problem in Python

nplusone nplusone is a library for detecting the n+1 queries problem in Python ORMs, including SQLAlchemy, Peewee, and the Django ORM. The Problem Man

Joshua Carp 837 Dec 29, 2022