klis87 / django-cloudinary-storage

Django package that provides Cloudinary storages for both media and static files as well as management commands for removing unnecessary files.
MIT License
131 stars 26 forks source link

Splitting static between Cloudinary and production server #6

Closed si14 closed 7 years ago

si14 commented 7 years ago

Hi there!

Do you think it would be hard to split static between Cloudinary and the "usual" manifest storage?Here is a use case I have: while Cloudinary's CDN is the best place for most of static stuff, a few critical resources (e.g. CSS) are pushed (with http2 push) on page load. Of course you can't push stuff from a different domain, so right now it's either CDN or http2 push. It would be nice to be able to skip CDN for some files.

One (simple) way of doing that is to override url() in my project. However, I'm not sure if it will not break something. What do you think?

klis87 commented 7 years ago

Interesting case :) This simple way is not the most convenient way to do it, because as I guess you need to save those static files yourself, which is not ideal, apart from this it could interfere with management commands.

The way I would do it is to create another storage, which would be parent to StaticHashedCloudinaryStorage and "usual" manifest storage (it would hold instances of its children). Then, based on some setting like CONDITIONAL_GLOB_PATTERNS, this storage could delegate given methods to correct storage. Unfortunately I don't have time to implement this myself right now, but if you wish, you could create a PR. If not, I will add this to my TODO list :)

si14 commented 7 years ago

Thanks! Will do and report on results in this issue.

klis87 commented 7 years ago

Actually after reconsideration, I am closing this issue. Having conditional storages shouldn't be part of this project, it could be completely separate project which a ConditionalStorage, which could dynamically select a given storage depending on some circumstances. Then, this issue could be solved in a general way.