[Django] #31447: ManifestStaticFilesStorage should have file exclude patterns

21 views
Skip to first unread message

Django

unread,
Apr 9, 2020, 1:06:43 PM4/9/20
to django-...@googlegroups.com
#31447: ManifestStaticFilesStorage should have file exclude patterns
-----------------------------------------------+------------------------
Reporter: Carsten Fuchs | Owner: nobody
Type: New feature | Status: new
Component: contrib.staticfiles | Version: 3.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 |
-----------------------------------------------+------------------------
`ManifestStaticFilesStorage` covers all files found by the static files
finders.
However, it is not always desirable to have all files covered:

- files for user download, e.g. `usermanual.pdf`:
- such files are not cached by browsers and thus require no cache
busting
- files with hashes in their file name impair the user experience
- files where the cache busting is done by other means:
- e.g. when an explicit version string is already kept in other
ways, e.g. manually as in `jquery-3.4.1.slim.min.js`

Thus it would be helpful if files could be excluded from the manifest
processing. For example, a setting with glob patterns could be introduced
such as:
{{{
#!python
STATICFILES_MANIFEST_EXCLUDES = (
"*.pdf",
"static/3rdparty/",
)
}}}
Does that make sense?

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

Django

unread,
Apr 10, 2020, 1:03:10 AM4/10/20
to django-...@googlegroups.com
#31447: ManifestStaticFilesStorage should have file exclude patterns.
-------------------------------------+-------------------------------------

Reporter: Carsten Fuchs | Owner: nobody
Type: New feature | Status: closed
Component: contrib.staticfiles | Version: 3.0
Severity: Normal | Resolution: wontfix

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

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


Comment:

A new setting is not necessary, you can use
[https://docs.djangoproject.com/en/3.0/ref/contrib/staticfiles/#cmdoption-
collectstatic-ignore the collectstatic --ignore option], see #28566.

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

Django

unread,
Apr 10, 2020, 3:04:08 AM4/10/20
to django-...@googlegroups.com
#31447: ManifestStaticFilesStorage should have file exclude patterns.
-------------------------------------+-------------------------------------

Reporter: Carsten Fuchs | Owner: nobody
Type: New feature | Status: closed
Component: contrib.staticfiles | Version: 3.0
Severity: Normal | Resolution: wontfix

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 Carsten Fuchs):

Hello Felix,

sorry, my description was probably not clear:
When we use `ManifestStaticFilesStorage`, the `collectstatic` command
copies and creates static files such that the result is, for example:
{{{
usermanual.4b127df11c35.pdf
usermanual.pdf
}}}
In a template, using `{% static 'usermanual.pdf' %}`, links to
`.../static/usermanual.4b127df11c35.pdf` are generated. What I intended
with the above suggested `STATICFILES_MANIFEST_EXCLUDES` setting is to
have only
{{{
usermanual.pdf
}}}
copied and `{% static 'usermanual.pdf' %}` generating a link to
`.../static/usermanual.pdf`, just as if not the manifest, but the default
`StaticFilesStorage` was used. (For all files not covered by
`STATICFILES_MANIFEST_EXCLUDES`, the hashed paths should be used.)

In contrast to that, `collectstatic --ignore` doesn't copy the ignored
files at all, causing `{% static 'usermanual.pdf' %}` to raise an
exception.

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

Django

unread,
Apr 10, 2020, 3:34:18 AM4/10/20
to django-...@googlegroups.com
#31447: ManifestStaticFilesStorage should have file exclude patterns.
-------------------------------------+-------------------------------------

Reporter: Carsten Fuchs | Owner: nobody
Type: New feature | Status: closed
Component: contrib.staticfiles | Version: 3.0
Severity: Normal | Resolution: wontfix

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 felixxm):

Replying to [comment:2 Carsten Fuchs]:


> Hello Felix,
>
> sorry, my description was probably not clear:
> When we use `ManifestStaticFilesStorage`, the `collectstatic` command
copies and creates static files such that the result is, for example:
> {{{
> usermanual.4b127df11c35.pdf
> usermanual.pdf
> }}}
> In a template, using `{% static 'usermanual.pdf' %}`, links to
`.../static/usermanual.4b127df11c35.pdf` are generated. What I intended
with the above suggested `STATICFILES_MANIFEST_EXCLUDES` setting is to
have only
> {{{
> usermanual.pdf
> }}}
> copied and `{% static 'usermanual.pdf' %}` generating a link to
`.../static/usermanual.pdf`, just as if not the manifest, but the default
`StaticFilesStorage` was used. (For all files not covered by
`STATICFILES_MANIFEST_EXCLUDES`, the hashed paths should be used.)
>
> In contrast to that, `collectstatic --ignore` doesn't copy the ignored
files at all, causing `{% static 'usermanual.pdf' %}` to raise an
exception.

You should be able to [https://docs.djangoproject.com/en/3.0/howto/custom-
file-storage/#writing-a-custom-storage-system write a custom] subclass of
[https://docs.djangoproject.com/en/3.0/ref/contrib/staticfiles/#manifeststaticfilesstorage
ManifestStaticFilesStorage] for this. We don't want to provide settings
for customizing the `ManifestStaticFilesStorage` behavior.

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

Django

unread,
Apr 10, 2020, 3:43:19 AM4/10/20
to django-...@googlegroups.com
#31447: ManifestStaticFilesStorage should have file exclude patterns.
-------------------------------------+-------------------------------------

Reporter: Carsten Fuchs | Owner: nobody
Type: New feature | Status: closed
Component: contrib.staticfiles | Version: 3.0
Severity: Normal | Resolution: wontfix

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 Carsten Fuchs):

Okay! I thought this might be of general interest, but reconsidering I
think you're right, this is better placed in a subclass. Thank you!

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

Reply all
Reply to author
Forward
0 new messages