Skip to main content

clears the junk out of your CSS

Project description

Build status

Clears the junk out of your CSS by finding out which selectors are actually not used in your HTML.

By Peter Bengtsson, 2012-2015

Tested in Python 2.7, 3.3 and 3.4

Example

$ mincss https://github.com

Installation

>From pip:

$ pip install mincss

Why?

With the onslaught of Twitter Bootstrap upon the world it’s very tempting to just download their whole fat 80+Kb CSS and serve it up even though you’re not using half of the HTML that it styles.

There’s also the case of websites that have changed over time but without the CSS getting the same amount of love refactoring. Then it’s very likely that you get CSS selectors that you’re no longer or never using.

This tool can help you get started reducing all those selectors that you’re not using.

Whitespace compression?

No, that’s a separate concern. This tool works independent of whitespace compression/optimization.

For example, if you have a build step or a runtime step that converts all your CSS files into one (concatenation) and trims away all the excess whitespace (compression) then the output CSS can still contain selectors that are never actually used.

What about AJAX?

If you have a script that creates DOM elements in some sort of window.onload event then mincss will not be able to know this because at the moment mincss is entirely static.

So what is a web developer to do? Simple, use /* no mincss */ like this for example:

.logged-in-info {
    /* no mincss */
    color: pink;
}

That tells mincss to ignore the whole block and all its selectors.

Ignore CSS

By default, mincss will find all <link rel="stylesheet" ... and <style...> tags and process them. If you have a link or an inline tag that you don’t want mincss to even notice, simply add this attribute to the tag:

data-mincss="ignore"

Leave CSS as is

One technique to have a specific CSS selector be ignored by mincss is to put in a comment like /* no mincss */ inside the CSS selectors block.

Another way is to leave the whole stylesheet as is. The advantage of doing this is if you have a link or style tag that you want mincss to ignore but still find and include in the parsed result.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mincss-0.11.3.tar.gz (13.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

mincss-0.11.3-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

mincss-0.11.3-py2-none-any.whl (14.9 kB view details)

Uploaded Python 2

File details

Details for the file mincss-0.11.3.tar.gz.

File metadata

  • Download URL: mincss-0.11.3.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for mincss-0.11.3.tar.gz
Algorithm Hash digest
SHA256 90fdb1429bc2d62c5067053d66ed9d908565a14f6beca76f871963627460800a
MD5 e399ac4b55a09c9fc930ed932de4ae9f
BLAKE2b-256 ec9afdeff35c1cafa3543d482b37c752aa91f0b758becc9adc486e8f514b6eaa

See more details on using hashes here.

File details

Details for the file mincss-0.11.3-py3-none-any.whl.

File metadata

File hashes

Hashes for mincss-0.11.3-py3-none-any.whl
Algorithm Hash digest
SHA256 582021bb896755b537337eb3bcd93c5737e7eccd3439a636d4f2422f8c1cd16f
MD5 cb9e23dc4e2ca107bc0a101ce4b5443c
BLAKE2b-256 090bbe1599a5599f9e1e5f646b0dc717ce2996b25a570baf2c7862aff0f2a482

See more details on using hashes here.

File details

Details for the file mincss-0.11.3-py2-none-any.whl.

File metadata

File hashes

Hashes for mincss-0.11.3-py2-none-any.whl
Algorithm Hash digest
SHA256 b5aca0e06cd132b7cde08749939b8e8dbea223dcbc4b5678399de4d743b3d520
MD5 24b955badedf06b764e51a865b5f41b9
BLAKE2b-256 93323d29dddfe9ed4bb334e914e99a95ca1edeada753d2ccf494ab575c89838f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page