开发者

What's the best way to pipeline assets to a CDN with Django?

开发者 https://www.devze.com 2023-03-29 13:16 出处:网络
When it comes time to deploy, one best practice is compressing static assets (js, css), and moving them to a CDN. There are a few Django apps that handle some aspects (django-compressor, django-pipeli

When it comes time to deploy, one best practice is compressing static assets (js, css), and moving them to a CDN. There are a few Django apps that handle some aspects (django-compressor, django-pipeline each come to mind), but they each have their own problems. For example,

  • django-compressor wants to generate content inside of the request/response loop, even when exclusively-offline compression is enabled.
  • django-pipeline doesn't store hashes anywhere, so it iterates through the path it writes compressed files to, regex-matches filenames, sorts those possible matches, and returns the last item in the list. Try doing this from a CDN! What?!

The (seemingly logical) pipeline workflow I'm looking for is this:

  1. Compress assets, using hashes of content for filename
  2. Stores those filena开发者_Python百科mes in a cache or a module or something that can be easily referenced when it's time to render the HTML.

I shouldn't have to have every static file on all of my web front-end nodes -- only the CDN.

Right now, I feel like my best option is to hack support for caching filename hashes into django-pipeline, but I'm dreaming of a drop-in solution for this.

What are my best options in Django for this? Are there any?

Thanks!


django-pipeline 1.1.12 is now caching hash, so you should be fine, see the changelog.

Disclaimer: I'm one of the author of django-pipeline.


Are you running Django 1.3? If so, then you can write your own custom file storage backend that uploads things to a CDN. Luckily, if you want to use Amazon S3, then django-storages already does exactly what you want!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号