Comments (8)
From PR #876, it looks like I'm supposed to add my own class that dynamically adds the SCRIPT_NAME prefix to the STATIC_URL (and COMPRESS_URL) (or am I supposed to use the LazyScriptNamePrefixedUrl
class from the test code)? Should this feature be documented?
from django-compressor.
This looks like you're hitting this issue in Django...
https://code.djangoproject.com/ticket/34028
The long and short is that script name doesn't really work outside of the request-response cycle, so not with compress.
You might need to adjust your static url when running the command (or else find a way of making it work)
from django-compressor.
Thanks, @carltongibson. I actually don't have any static url in the compressed asset itself - this is just an issue with linking to the compressed asset when the response is generated.
I tried adding the LazyScriptNamePrefixedUrl
class to my settings.py, and used that for COMPRESS_URL
, and now it looks like the URL to the compressed asset does correctly contain the SCRIPT_NAME value.
So it looks like the feature does work, if the user adds a str
subclass and uses that in their settings. Should this be added to the documentation?
from django-compressor.
...this is just an issue with linking to the compressed asset when the response is generated.
Following the discussion on the linked Django issue, in this circumstance SRIPT_NAME
should be working no? 🤔
Maybe it's an issue with Django, maybe it's a configuration issue, but a minimal reproduce on a fresh project, and a report to Django is likely the way to go.
I don't think it's a compressor issue per se? 🤔 (Using the utility from compressor's test suite looks like patching over any issue, rather than addressing it 😬)
from django-compressor.
Reviewing the docs for FORCE_SCRIPT_NAME
, SCRIPT_NAME
is part of the WSGI environment, rather than an HTTP header, so I think you'd need to set it in your wsgi.py, or gunicorn config, rather than setting it as an HTTP header in Nginx.
https://docs.djangoproject.com/en/4.2/ref/settings/#force-script-name
Update: Although the gunicorn FAQ seems to imply either would be good: https://docs.gunicorn.org/en/stable/faq.html — you'll need to experiment to pin down exactly the behaviour.
from django-compressor.
@carltongibson thanks again for your comments.
Here's a question: if I want to mount my app at different prefixes (eg. /foo
and /bar
) at the same time (with offline compression and compressed assets served from /foo/static
and /bar/static
), does compressor
support that? If so, how should I configure it (especially the COMPRESS_URL)?
What I'm seeing locally is that if I set COMPRESS_URL to a regular value like /static
, the SCRIPT_NAME doesn't get added to the links on the page to the compressed assets. If I make the COMPRESS_URL a dynamic value where I add the SCRIPT_NAME on each call (ie. using the class from the compressor
tests), then it works. (This seems to fit with what I see in the PR #876 where the feature was added.)
from django-compressor.
Grr. I'd have to play. (And there's not enough info, or a quick reproduce here, so that I can do that.) I'd reckon per-deploy settings with slight tweaks would do it. (I saw you commented about the offline context on another issue...)
from django-compressor.
Here's a playground project: https://github.com/bcail/dj_playground. I'm running it with: DJANGO_SETTINGS_MODULE=playground.settings gunicorn playground.wsgi:application
Here's my nginx config:
location /foo/static {
alias /var/www/playground_static;
}
location /bar/static {
alias /var/www/playground_static;
}
location /foo {
proxy_pass http://localhost:8000;
proxy_set_header SCRIPT_NAME /foo;
}
location /bar {
proxy_pass http://localhost:8000;
proxy_set_header SCRIPT_NAME /bar;
}
playground/settings.py
has two options for COMPRESS_URL
, one commented out. If I use the normal /static
value, the compressed asset doesn't work. If I change it to the LazyScriptNamePrefixedUrl
value, then the compressed asset works on both /foo/polls
and /bar/polls
.
from django-compressor.
Related Issues (20)
- Please update readthedocs with release 4.2 and 4.3 HOT 4
- Slim down package HOT 1
- Add support for django 4.2 HOT 1
- Replace deprecated imp module with importlib HOT 2
- Django's `get_storage_class` is deprecated in 4.2 (Django 5.1 compat.) HOT 5
- Releasing a new version with Django 4.2 support HOT 3
- No way to specify hashing method for JS files? HOT 1
- Disable offline compression for some scripts HOT 5
- Fix tests with Python 3.9.17, 3.10.12 and 3.11.4 HOT 7
- Dependencies are pinned HOT 1
- Getting more info when `Error parsing template` happens
- Not compatible with django-components HOT 10
- Issue with losing templates in compress command in version >=3.0.
- optional max_workers for compress command HOT 1
- 'Settings' object has no attribute 'COMPRESSORS' HOT 8
- OSSFuzz Integration HOT 4
- 4.4: compressor.exceptions.OfflineGenerationError raised in tests HOT 4
- Django 5.1 compatibility HOT 1
- Offline compression + inlining bug HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-compressor.