Django Static Stuff

Django Static Stuff

Handling the Un-Django Parts of Your Django App

0e631d686b8356102da3721bd8cd65c4?s=128

Matthew Dapena-Tretter

July 10, 2013
Tweet

Transcript

  1. STATIC STUFF Handling the Un-Django Parts of Your Django App

    Matthew Tretter @matthewwithanm m@tthewwithanm.com github.com/matthewwithanm http://speakerdeck.com/matthewwithanm/django-static-stuff
  2. Photo by Jeff Prouse http://www.flickr.com/photos/prousefamily/426140767/ Static files used to be

    a small problem for Django devs
  3. Photo by John R. Southern http://www.flickr.com/photos/krunkwerke/267608325 Now, they’re a much

    larger problem
  4. None
  5. None
  6. None
  7. Photo by Brin F http://thumbsandammo.blogspot.com/2013/03/blog-post_4297.html

  8. ⃠ {% load static %}

  9. def static(path): return settings.STATIC_URL + path

  10. {% load staticfiles %}

  11. {% load static from staticfiles %}

  12. {% load static from staticfiles %} Delegates to STATICFILES_STORAGE

  13. main.css main.af42991c673a.css Wow, this slide is boring. CachedStaticFilesStorage CachedFilesMixin

  14. You can’t tell your users to clear their cache Far-future

    FTW Safer deployments Photo by patriziasoliani http://www.flickr.com/photos/55524309@N05/5378314720/
  15. Why not django-compressor?

  16. input defined in templates doesn’t know about dependency graphs only

    for js & css
  17. Embrace the build step Photo by Phyllis Buchanan http://www.flickr.com/photos/pgautier/2598157781/

  18. 1.Collect the static files from all apps into temporary location

    2.Perform the build 3.Collect the built files Photo by Spencer Garness http://www.flickr.com/photos/njorthr/4030750472/
  19. None
  20. sass/lessc coffee uglify.js csso Photo by Toni http://www.flickr.com/photos/toniandmatthew/5212240990/

  21. sass/lessc coffee uglify.js csso Photo by Toni http://www.flickr.com/photos/toniandmatthew/5212240990/ r.js jpegtran

    pngcrush svgo
  22. sass/lessc coffee uglify.js csso r.js jpegtran pngcrush svgo ANYTHING It’s

    still the same photo
  23. Can we do better? Yeah, still. Sorry.

  24. Embrace Django

  25. Photo by Brin F. But it’s slightly different than before!

    No it’s not. http://thumbsandammo.blogspot.com/2013/03/blog-post_4297.html
  26. generate & consume static file manifests tweak post-processing improve collection

  27. TL;DL

  28. {% load staticfiles %}

  29. Hashes in Filenames

  30. Embrace the build step

  31. Build on staticfiles app

  32. Thanks http://speakerdeck.com/matthewwithanm/django-static-stuff https://gist.github.com/matthewwithanm/5969795 Matthew Tretter @matthewwithanm m@tthewwithanm.com github.com/matthewwithanm