skip to Main Content

I have a Django website that displays a table with data. It uses FontAwesome and Bootstrap for styling – which leads to some lengthy HTML (a standard page is 136k).

Eg Some TDs contain an arrow using FA and a style to rotate it eg

<i class="fa-solid fa-arrow-down fa-lg fa-rotate-by" style=--fa-rotate-angle:282deg></i>

Is there a way to minify or some how reduce the name sizes?

I have been reading about webpack and gulp minifiers but I cannot find anything that mentions the use of 3rd party assets like FA and BS and how one might reduce their name sizes. Also these seem somewhat targeted to client-side frameworks rather than server-side which mine is.

2

Answers


    • By HTML Minification

       - pip install htmlmin
       - MIDDLEWARE = ['path.to.minify_middleware.Minify',]
      

    from htmlmin.minify import html_minify #import minify

    class Minify:

    def __init__(self, get_response):
        self.get_response =get_response
    
    def __call__(self, request):
        response = self.get_response(request)
        if "text/html" in response.get('Content-Type', ''):
            response.content = html_minify(response.content.decode('utf-8'))
        return response
    
       
    
    Login or Signup to reply.
  1. Alternatively, by HTTP compression, if the intent is not to obfusticate your code at the browser end but to reduce bandwidth consumed. Django comes with gzip middleware, or there’s django-compression-middleware. which suppports other compression methods.

    I believe, but haven’t measured, that HTTP compression will save more bandwidth than minification. It’s also install-and-forget.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search