meeb/django-distill

Make copying of existing staticfiles and media optional

Closed this issue · 4 comments

In my case, I want to serve distilled files as static files via Whitenoise.
Therefore I store disitilled files in my STATIC_ROOT.
Unfortunately, django-distill copies all existing staticfiles and media files into subfolder static in DISTILL_DIR when running distill-local - and thus all files are copied unnecessarily.

I created a PR in which copying of staticfiles and media can be suppressed by giving an extra option --exclude-staticfiles. Maybe this is also helpful for others?
See my branch https://github.com/henhuy/django-distill/tree/optional_static_and_media

meeb commented

Running a Django site where you output static HTML pages to serve via a static web server but want to run the static assets behind an application server (like Django running via a WSGI server) is a pretty weird setup. What's the practical point of deploying in this method? If there's a good reason to do this I've overlooked I'll consider your PR. By default, the distill-local command doesn't chain to collectstatic anyway, you could always just rm -rf static/* before calling distill-local if you have some niche requirement as well.

I want to serve geodata using restframework-gis.
Therefore I thought it might be faster to pre-render the views (aka geojsons) and serve them as static files.
Maybe I have to overthink my setup... (will make some preformance tests and see what's happening)

meeb commented

Typically for a setup like that you wouldn't attempt to create all the static versions of the output of your API on disk. Assuming your data doesn't change that much the far easier option would be to just put the API behind nginx or some other high performance web server and enable 24h of caching or some similar extended caching timeframe.

Personally, I use nginx directly caching to a memcached cluster to achieve these sorts of deployments. As there is no disk IO it's even faster than using static files on disk. If you're feeling fancy and want to flush some of the data early you can also just send a delete to the memcached cluster for the key you want to refresh. For your deployment I wouldn't particularly suggest a static template system to write out all permutations of your data.

Thanks for your recommendations! I will keep them in mind!
FYI - I just tested to load a geojson data of 5MB into my map - using the same rest-framework view for all tests.
Here performances:

  • standard:
    • no cache: ~400ms
  • distill:
    • no cache: ~200ms