[Django] #29265: Docs about static files should explain benefits of using {% static %} template tag

14 views
Skip to first unread message

Django

unread,
Mar 27, 2018, 1:33:47 AM3/27/18
to django-...@googlegroups.com
#29265: Docs about static files should explain benefits of using {% static %}
template tag
------------------------------------------------+------------------------
Reporter: Ryan Govostes | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 2.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
The [https://docs.djangoproject.com/en/2.0/howto/static-files/ guide on
managing static files] says,

In your templates, either hardcode the url like
`/static/my_app/example.jpg` or, preferably, use the `static` template tag
to build the URL for the given relative path by using the configured
`STATICFILES_STORAGE` storage (this makes it much easier when you want to
switch to a content delivery network (CDN) for serving static files).

(Nit: The first "url" should be capitalized.)

The text alludes to but does not really explain that if you use a static
files storage backend that inherits from `ManifestStaticFilesStorage`, the
`static` template tag will use the name of the hashed file in production,
which enables longer-lived caches.

Since the behavior is different in debug mode, I think many users will not
even know about it, and fail to opt-in to the better caching behavior by
hard-coding paths. (The files storage backend is turned on if the
developer follows the WhiteNoise setup guide, or when using the Heroku app
template, neither of which specifically calls out the need to use
`static`.)

--
Ticket URL: <https://code.djangoproject.com/ticket/29265>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 27, 2018, 1:34:48 AM3/27/18
to django-...@googlegroups.com
#29265: Docs about static files should explain benefits of using {% static %}
template tag
-------------------------------------+-------------------------------------

Reporter: Ryan Govostes | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Documentation | Version: 2.0
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Ryan Govostes):

I don't strongly see the reason to bring up the option of hardcoding the
URLs at all, rather than only recommending the best practice.

--
Ticket URL: <https://code.djangoproject.com/ticket/29265#comment:1>

Django

unread,
Mar 28, 2018, 11:17:13 AM3/28/18
to django-...@googlegroups.com
#29265: Docs about static files should explain benefits of using {% static %}
template tag
--------------------------------------+------------------------------------

Reporter: Ryan Govostes | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 2.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham):

* has_patch: 0 => 1
* stage: Unreviewed => Accepted


Comment:

I agree there's no reason to mention hardcoding URLs.
[https://github.com/django/django/pull/9831 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/29265#comment:2>

Django

unread,
Mar 28, 2018, 12:35:35 PM3/28/18
to django-...@googlegroups.com
#29265: Docs about static files should explain benefits of using {% static %}
template tag
--------------------------------------+------------------------------------

Reporter: Ryan Govostes | Owner: nobody
Type: Cleanup/optimization | Status: closed
Component: Documentation | Version: 2.0
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"ba5f24ea6491780bb245ed6f0e5f015f4defffe9" ba5f24e]:
{{{
#!CommitTicketReference repository=""
revision="ba5f24ea6491780bb245ed6f0e5f015f4defffe9"
Fixed #29265 -- Removed the suggestion to hardcode static URLs.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29265#comment:3>

Django

unread,
Mar 28, 2018, 12:35:51 PM3/28/18
to django-...@googlegroups.com
#29265: Docs about static files should explain benefits of using {% static %}
template tag
--------------------------------------+------------------------------------

Reporter: Ryan Govostes | Owner: nobody
Type: Cleanup/optimization | Status: closed
Component: Documentation | Version: 2.0

Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"a3007ecf3541ab319892809cf5ea7d7487667ef0" a3007ecf]:
{{{
#!CommitTicketReference repository=""
revision="a3007ecf3541ab319892809cf5ea7d7487667ef0"
[2.0.x] Fixed #29265 -- Removed the suggestion to hardcode static URLs.

Backport of ba5f24ea6491780bb245ed6f0e5f015f4defffe9 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29265#comment:4>

Reply all
Reply to author
Forward
0 new messages