4

Django-Compressor Tricks and Gotchas | Snakey Code

 3 years ago
source link: https://snakeycode.wordpress.com/2021/02/07/django-compressor-tricks-and-gotchas/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Django-Compressor Tricks and Gotchas

Although it looks simple enough, getting Django-Compressor working is a little tricky. Here are my notes.

Do Not Nest {% Compress %} Blocks

This one comes from https://blog.imposeren.org/2012/10/django-compressor-notes-and-tricks.html

If you accidentally nest blocks you will get an error like this:

You have offline compression enabled but key "%s" is missing from offline manifest.

Make Sure Your Server is Setup to Server GZIP

If you do offline compression, then django-compressor will create a minified file and a compressed (*.gz) file. The content on your page will point to the minified file. It is up to your server to send the *.gz version when the minified version is requested.

In nginx, the setting that does that is:

location / {
    gzip_static on;
}

To make sure the gzip version is being used, make sure the “Content-Encoding” of the response header is “gzip”.

Test Run “compress” Locally

One of the tricky things about using django-compressor is it is off when DEBUG is True. This means you can have problems with your *.html files and not know about them until you push them to a server.

In order to find those errors, I have a settings file that is my dev settings along with DEBUG=False and the COMPRESS settings from production. This allows the “compress” command to be run locally.

Beware of Context Variables in your Javascript

This is an easy mistake to make. Maybe your page has a dynamic link and you are using something like:

const url = "{% url 'my_url' var1 %}";

The problem with this is var1 is not defined at the time the offline compression is done. There are lots of ways to handle this, including using some of the django-compressor settings.

Advertisements
Report this ad

Recommend

  • 10
    • www.mikechambers.com 4 years ago
    • Cache

    Flash / Arduino Tips, Tricks and Gotchas

    This is a ongoing post where I will post tips, tricks and gotchas that I learn while developing with Flash and the Arduino. I will update this from time to time with more information. Make sure you are using the correct BAUD Rate

  • 9
    • blog.imposeren.org 4 years ago
    • Cache

    Django-compressor notes and tricks

    Django-compressor notes and tricks If you'd like to have offline compression enabled then do not do next things: Do not use nested css/js blocks that are extended in templates. Example of "bad" templates:site_bas...

  • 6
    • snakeycode.wordpress.com 3 years ago
    • Cache

    Video Capture Frame Colors Are Wrong | Snakey Code

    Standard Video Capture Frame Colors Are Wrong I wanted to grab some images from a .mov video taken with my iPhone and process them with Pillow. There are lots of tutorials on how to...

  • 5

    Creating Responsive Content Using Google Web Designer I am not a graphic designer and do not want to be a graphic designer. In my case, I just wanted a single responsive banner ad with simple design. I probably only used about 5...

  • 13
    • snakeycode.wordpress.com 3 years ago
    • Cache

    Using FoxDot on Mac OS 12 | Snakey Code

    Using FoxDot on Mac OS 12 I had trouble getting this working. I do not recall everything I did to get this working. But these notes might help. Mac OS 12SuperCollider 3.12.1FoxDot 0.8.12

  • 9
    • snakeycode.wordpress.com 3 years ago
    • Cache

    Tensorflow Conv1D | Snakey Code

    Tensorflow Conv1D The Tensorflow Conv1D layer is useful for time series analysis. Just like Conv2D for image analysis, Conv1D reduces the number of weights in the model by sharing the weights.

  • 15
    • snakeycode.wordpress.com 3 years ago
    • Cache

    File Uploads Using Django FormView | Snakey Code

    File Uploads Using Django FormView As of Django 3.1, the documentation did not show how to upload files with the Django class based view; FormView. To accomplish this, go to the

  • 15

    Problems w pyodbc and pymssql on Python 2.7 I am writing this in Feb 2021. Due to circumstances beyond my control, I am forced to use Python 2.7. For many years I have been using pyodbc to connect to a remote SQL...

  • 9

    Feature 5 old social engineering tricks employees still fall for, and 4 new gotchas Despite all the trainin...

  • 10
    • www.percona.com 2 years ago
    • Cache

    Replication Issues and Binlog Compressor

    Replication Issues and Binlog Compressor March 24, 2023 Denis Subbota ...

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK