On Thu, Jul 5, 2012 at 5:00 PM, Russell Keith-Magee <russ...@keith-magee.com
> wrote:

> On Fri, Jul 6, 2012 at 4:27 AM, David Lam <david.k.l...@gmail.com> wrote:
> > hmm, kinda semi-noob, but heres my scenario
> >
> > I just started working on a fairly large Django project thats been around
> > for a couple years.
> >
> > In the templates,  I see a lot of use of {% spaceless %} tags whose
> apparent
> > function is solely to trim whitespace to reduce page size/page load time
> or
> > something.
> >
> > That's not really what it was made for right?
>
> Good question. I'm not really sure *what* it's supposed to be used
> for. Trimming whitespace to reduce page size is one possible use; the
> other is to 'humanize' the output of a block of template code that has
> a lot of control structures in it (i.e., a template with lots of {% if
> %} and {% for %} clauses will cause lots of blank lines and whitespace
> to be injected into a template, which is a bit messy and painful to
> read.
>
> However, for me, neither of these are particularly compelling uses.
>
> HTML code isn't supposed to be human readable, and all the modern
> tools (Firebug, Safari/Chrome inspect tools) parse the markup and show
> you DOM trees, not raw HTML code. And if you're worried about page
> size from a performance point of view, you're going to get much better
> results by turning on GZip compression in your response headers.
>
> So why is {% spaceless %} in the template language? Well, it was added
> in the early days of Django, when we were on a "accept everything in
> order to build community" drive. I suspect the thinking didn't go much
> further than "Yeah, I can see how that might be helpful; you've
> provided a patch, so lets add it".  With the benefit of hindsight, it
> probably isn't as useful as we originally hoped. Now it's there, and
> we'd have to go through a deprecation cycle (and probably a bunch of
> painful "But I *really* need it" arguments on django-dev), so it's
> easier to just live and let live.
>
> I haven't done any testing to be sure, but it certainly wouldn't
> surprise me if there's a non-trivial performance hit associated with
> using spaceless. If you're performance tuning a site, and you don't
> have any other reason for using spaceless (e.g., rendering a
> whitespace-significant output language), I wouldn't argue against
> removing uses of spaceless as a performance improvement.
>

ahhhhh cool,  thanks for the insight on the history of it

if it's really the case that {% spaceless %} shouldn't be used for
minifying white space on a page, I think it'd be useful to have a doc note
that discourages it or something -->
https://docs.djangoproject.com/en/dev/ref/templates/builtins/#spaceless

something like,  "If you wanna reduce page size, its better to use web
server gzip compression than to put {% spaceless %} tags everywhere.  The
spaceless tag was/is intended for... "

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to