Slide 1

Slide 1 text

STATIC STUFF Handling the Un-Django Parts of Your Django App Matthew Tretter @matthewwithanm [email protected] github.com/matthewwithanm http://speakerdeck.com/matthewwithanm/django-static-stuff

Slide 2

Slide 2 text

Photo by Jeff Prouse http://www.flickr.com/photos/prousefamily/426140767/ Static files used to be a small problem for Django devs

Slide 3

Slide 3 text

Photo by John R. Southern http://www.flickr.com/photos/krunkwerke/267608325 Now, they’re a much larger problem

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

Photo by Brin F http://thumbsandammo.blogspot.com/2013/03/blog-post_4297.html

Slide 10

Slide 10 text

⃠ {% load static %}

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

{% load staticfiles %}

Slide 13

Slide 13 text

{% load static from staticfiles %}

Slide 14

Slide 14 text

{% load static from staticfiles %} Delegates to STATICFILES_STORAGE

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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/

Slide 17

Slide 17 text

Why not django-compressor?

Slide 18

Slide 18 text

input defined in templates doesn’t know about dependency graphs only for js & css

Slide 19

Slide 19 text

Embrace the build step Photo by Phyllis Buchanan http://www.flickr.com/photos/pgautier/2598157781/

Slide 20

Slide 20 text

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/

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

sass/lessc coffee uglify.js csso r.js jpegtran pngcrush svgo ANYTHING It’s still the same photo

Slide 25

Slide 25 text

Can we do better? Yeah, still. Sorry.

Slide 26

Slide 26 text

Embrace Django

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

generate & consume static file manifests tweak post-processing improve collection

Slide 29

Slide 29 text

TL;DL

Slide 30

Slide 30 text

{% load staticfiles %}

Slide 31

Slide 31 text

Hashes in Filenames

Slide 32

Slide 32 text

Embrace the build step

Slide 33

Slide 33 text

Build on staticfiles app

Slide 34

Slide 34 text

Thanks http://speakerdeck.com/matthewwithanm/django-static-stuff https://gist.github.com/matthewwithanm/5969795 Matthew Tretter @matthewwithanm [email protected] github.com/matthewwithanm