Adds support for modern browsers to conditionally GET responses based on the
``ETag`` and ``Last-Modified`` headers.
:class:`~django.middleware.gzip.GZipMiddleware`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Compresses responses for all modern browsers, saving bandwidth and transfer
time. Note that GZipMiddleware is currently considered a security risk, and is
vulnerable to attacks that nullify the protection provided by TLS/SSL. See the
warning in :class:`~django.middleware.gzip.GZipMiddleware` for more information.
Third-party HTTP tools
----------------------
There are numerous third-party Django tools and packages available, notably
ones that are able to "minify" and compress HTML, CSS and JavaScript.
Template performance
====================
Note that:
* using ``{% block %}`` is faster than using ``{% include %}``
* heavily-fragmented templates, assembled from many small pieces, can affect
performance
The cached template loader
--------------------------
Enabling the :class:`cached template loader
<django.template.loaders.cached.Loader>` often improves performance
drastically, as it avoids compiling each template every time it needs to be
rendered.
Using different versions of available software
==============================================
It can sometimes be worth checking whether different and better-performing
versions of the software that you're using are available.
This may be helpful, but is unlikely to solve a serious performance problem.
You won't usually gain performance advantages that are better than marginal.
.. note::
It's worth repeating: **reaching for alternatives to software you're
already using is very rarely the answer to performance problems**.
Newer is often - but not always - better
----------------------------------------
It's fairly rare for a new release of well-maintained software to be less
efficient, but the maintainers can't anticipate every possible use-case - so
while being aware that newer versions are likely to perform better, don't
simply assume that they always will.
This is true of Django itself. Successive releases have offered a number of
improvements across the system, but you should still check the real-world
performance of your application, because in some cases you may find that
changes mean it performs worse rather than better.
Newer versions of Python, and also of Python packages, will often perform
better too - but measure, rather than assume.
.. note::
Unless you've encountered an unusual performance problem in a particular
version, you'll generally find better features, reliability, and security
in a new release and that these benefits are far more significant than any
performance you might win or lose.
Alternatives to Django's template language
------------------------------------------
For nearly all cases, Django's built-in template language is perfectly
adequate. However, if the bottlenecks in your Django project seem to lie in the
template system and you have exhausted other opportunities to remedy this, a
third-party alternative may be the answer.
`Jinja2 <http://jinja.pocoo.org/docs/>`_ can offer performance improvements,
particularly when it comes to speed.
Alternative template systems vary in the extent to which they share Django's
templating language.
.. note::
*If* you experience performance issues in templates, the first thing to do
is to understand exactly why. Using an alternative template system may
prove faster, but the same gains may also be available without going to
that trouble - for example, expensive processing and logic in your
templates could be done more efficiently in your views.
Alternative software implementations
------------------------------------
It *may* be worth checking whether Python software you're using has been
provided in a different implementation that can execute the same code faster.
However, most Django performance problems in well-written code are typically
not to be found at the Python execution level, but rather in inefficient
database querying, caching, and templates (and if you're relying on
poorly-written Python code, your performance problems are very unlikely to be
solved by having it execute faster).
Avoid using C implementations of Python libraries or non-standard Python
implementations like `PyPy <http://pypy.org/>`_ in search of performance gains,
unless you are sure they are appropriate for your application. Any gains are
likely to be small, and compatibility issues are common.
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.