How do I serve static assets when using Enclave?


This article is about static assets served by your app such as CSS or JavaScript files.

If you’re looking for strategies for storing files uploaded by or generated for your customers, see How do I accept file uploads when using Enclave? instead.

Broadly speaking, there are two ways to serve static assets from an Aptible web app:

  • Store the assets in the Aptible container, and serve them from Aptible.
  • Store the assets in a third-party object store (like AWS S3)

The latter approach has a performance advantage: serving static assets from S3 (or AWS CloudFront) is much faster than serving them from Enclave.

To precompile your assets and upload them to S3 before each new release of your app, you can use a before_release command.

For example, if you’re running a Rails app and using the Asset Sync gem to automatically sync your assets to S3 at the end of the Rails assets pipeline, you might use the following .aptible.yml file:

  bundle exec rake assets:precompile