Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django spaceless template tag advantages

I've been wondering about this a lot recently, what is exactly the purpose of Django's spaceless template tag?

Obviously it removes whitespaces from HTML tags, but other than that does it increase the speed at which the pages load?

What I mean to ask is, does removing whitespaces from html files help in any way?

like image 292
Jonathan Avatar asked Feb 08 '13 04:02

Jonathan


1 Answers

A newline/space is a character, yes, and it will increase file size especially with large loops and human readability optimized template files (like a large FK list).

It's also exceedingly easy and safe to throw in {% spaceless %} in a base template.

It also lets you keep template code indented for readability but properly spaceless for HTML rendering (I'm thinking commas are a common scenario).

like image 189
Yuji 'Tomita' Tomita Avatar answered Sep 23 '22 05:09

Yuji 'Tomita' Tomita