Volt Introduction and Docs

Volt Deployment

Running in Production

When you deploy your app, it is reccomended that you run volt with the VOLT_ENV=production environment variable set. This will disable code reloading and sourcemaps and enable some performance boosting settings (at the cost of load time).

Asset Precompilation

In volt, you can precompile all of your apps assets to a /public folder. When precompiling, Volt does the following:

  1. precompiles all opal files
  2. minifies JS/opal js (via uglifier)
  3. minified CSS (via csso)
  4. concat css and javascript into single files (to make less requests on the clients)
  5. lossless compresses all images and strip metadata (using various tools with image-optim)
  6. rename assets using fingerprinting, so the assets can be cached forever. (Because if the file changes, a new fingerprint will be generated and linked to)

All assets will be compiled into the /public folder, which you can serve directly via something like nginx. Precompiling results in a substantial initial page load speed boost, and results in fewer requests from the browser.

To precompile your app's assets, simply run:

VOLT_ENV=production bundle exec volt precompile

Asset Caching

Asset precompiling copies images referenced in css/sass/html files from components into the public folder. You may notice that all assets are renamed during precompiling to have a fingerprint hash on the end (eg: profile-) This lets you cache all images/fonts/etc. in the public folder for an indefinite amount of time. If the contents of the file changes, a new hash will be assigned. (This is the same process used by rails, see their much more complete docs for more info)

See the Assets section for details on setting up image tags, css, etc. to point to assets correctly.

Custom Socket Url

Volt does all database queries, updates, task calls, etc.. through a websocket connection. Websockets are created by "Upgrading" existing http connections. Typically volt will use the existing http connection to setup the websockets connection. However sometimes you may need to connect to the websocket through a different domain, port, etc.. (usually due to the main app running behind a non-websocket compatible proxy server). You can configure the websocket url in config/app.rb like so:

# ...

Volt.configure do |config|
  # ...

  config.public.websocket_url = 'websocket.mysite.com/socket'
  # ...

Volt will automatically add ws:// or wss:// to the front of the url if not specified.

Hosting Providers

The rest of this chapter highlights various deployment options for Volt on popular cloud providers.