miracle2k/django-assets

General confusion while working on multiple webservers with a CDN

Closed this issue · 1 comments

There are a couple issues we're seeing with the way django-assets has decided to integrate with webassets.

The relationship with collectstatic is especially confusing. By django's definition, collectstatic places the static files in the location that they will be served, so if you're using a CDN, this location is remote. assets build expects collectstatic to have been called, placing the files in the ASSETS_ROOT, and cannot (and shouldn't) build from a remote location. If we have collectstatic drop the files on the file system, assets build will work, but then there's no integrated way to upload to s3.

The other issue is with a remote manifest. Once we run assets build the manifest is updated, but the files haven't been uploaded, which causes pages to request compiled assets that don't yet exist.

There are two possible changes I can think of to fix this

  1. django-assets always uses staticfinders so collect static assets. collectstatic can then be used to upload to s3. This doesn't totally solve the remote manifest, but that can be fixed by running assets build with a dummy manifest, then collectstatic, then assets build again to update the manifest.
  2. (better solution) - use collectstatic to place the files in the correct directory and then have assets build honor django STATICFILES_STORAGES to upload the files before updating the manifest. This obviously means changes in webassets as well.

It looks like this has all been discussed here:

miracle2k/webassets#62

Let me know if I'm missing anything.

How do you think this would best be fixed?

I personally ignore AssetsFinder and simply use AppDirectoriesFinder and then first run assets build to dump compiled assets into a dummy app that I only use for this purpose. Then when I run collectstatic, it picks up all my static files (including the compiled ones) and uploads them to S3.