This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description
django-critical
===============

Inlines critical path CSS and defers loading full CSS asynchronously.

How it works
------------

`django-critical` parses the HTML between `{% critical %}` and `{% endcritical
%}` and searches for CSS.

```html
{% critical %}
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<style>
.jumbotron h1 {
color: red;
}
</style>
{% endcritical %}
```

It downloads and concatenates all CSS that it finds and uses
[penthouse](https://github.com/pocketjoso/penthouse/) to extract the
critical path CSS rules from it, which end up inlined and minified in place of
the original CSS.

```html
<style>html{font-family:sans-serif;-webkit-text-size-adjust:100%…</style>
```

Later in the HTML, before the closing `</body>` tag, the `{% critical_async %}`
template tag takes care of loading the rest of the CSS using FilamentGroup's
[loadCSS](https://github.com/filamentgroup/loadCSS)

Installation
------------

* Install `django-critical`:

```sh
pip install django-critical
```

* Add `critical` to your `INSTALLED_APPS` setting:

```python
INSTALLED_APPS = (
# other apps
"critical",
)
```

* Add `critical.middleware.CriticalCssMiddleware` to your `MIDDLEWARE_CLASSES`
setting:

```python
MIDDLEWARE_CLASSES = (
# other middlewares
"critical.middleware.CriticalCssMiddleware",
)
```

* Point your `CRITICAL_PENTHOUSE_PATH` setting to the correct path, e.g.:

```python
CRITICAL_PENTHOUSE_PATH = os.path.join(
BASE_DIR, 'node_modules/penthouse/penthouse.js')
```

Caching
-------

`django-critical` calculates the critical path CSS for the first request, caches
the result and reuses this CSS verbatim for further requests. Most web
applications have different critical path CSS for different groups of pages,
though. This can be solved using the `{% critical_key "<key>" %}` template tag,
so that different templates can have different caching keys.

Is this stable and ready for production use?
--------------------------------------------

No. `django-critical` is in a very early stage of development, so you should use
it at your own risk. [Bug
reports](https://github.com/martinblech/django-critical/issues) and
[contributions](https://github.com/martinblech/django-critical/pulls) are
welcome, though!
Release History

Release History

0.1

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
django-critical-0.1.tar.gz (6.4 kB) Copy SHA256 Checksum SHA256 Source Aug 5, 2014

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting