-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disable staticfiles.storage to generate URLs #86
Comments
@petrprikryl Thank you for addressing this issue. I ran into this problem during development of an inertia.js application. As you mentioned the entrypoint was requested via This resulted in very unclear errors in my application and I couldn't figure out why. Eventually I noticed the main file twice in the request tab of the browser console. After I found this issue I tried the I like your suggestion to control this feature via a setting. Maybe it should even be disabled by default when the |
Eventually solved this by adding a custom class ManifestStaticFilesStorage(ManifestFilesMixin, GoogleCloudStorage):
vite_hash_pattern = r"^.+[\.-][0-9a-zA-Z_-]{8,12}\..+$"
def url(self, name, force=False):
# if the file already has a hash, we don't need the django hashed file
if re.match(self.vite_hash_pattern, name):
return super(HashedFilesMixin, self).url(name)
return super().url(name, force) |
I came up with a solution similar to @svengt, but this way skips hashing the vite files alltogether (based on https://github.com/TomAnthony/django-flexible-manifest-staticfiles): (in our case all vite output is identifiable by the directory it's stored in, so no need for a regex) def _is_excluded(name):
return name.startswith("vite/")
class SelectiveManifestStaticFilesStorage(ManifestStaticFilesStorage):
def hashed_name(self, name, content=None, filename=None):
if _is_excluded(name):
return name
else:
return super().hashed_name(name, content, filename) |
Staticfiles serving was implemented to leverage Django's new support_js_module_import_aggregation.
But I think it is not production ready yet. On my projects it is not working either.
Next, without
support_js_module_import_aggregation
it could be very dangerous to provide 2 versions of JS module.Assume this scenario:
django-vite
providesentrypoint.<vitehash>.<djangohash>
djangohash
becasue files were not processed by Django. So the entrypoint is re-evaluated and our app crash.I think static files should be used only with
support_js_module_import_aggregation
. So it make sense to introduce something likeDJANGO_VITE_USE_STATICFILES
to be able to control it. Or even better to check ifSTATICFILES_STORAGE
has enabledsupport_js_module_import_aggregation
?Btw. compression works in
whitenoise
even if the file is served directly as original,entrypoint.<vitehash>
in our case.The text was updated successfully, but these errors were encountered: