Best Practices
Deploy Assets Before Documents

by Eric Fortis

When deploying, there’s a tiny window in which users could fetch a new document while its images, CSS, or JS files are still being uploaded. This results in broken or unstyled pages, similar to FOUCs.

As the problem is an uncoordinated deployment, one way to prevent those issues is by nesting the assets in subdirectories:

  • index.html
  • scripts/foo.js
  • media/bar.png

…and deploying in two steps:

# Subdirectories first
rsync -r --include '*/' --exclude '/*' $SRC/ $DEST/

# Then the top level files (HTML documents)
rsync --times $SRC/* $DEST

Although the preserving times flag (--times) is optional, it has benefits. They are explained in Hitting 304s Across Servers.

Sponsored by: