Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Serving Assets

Karol Bucek edited this page · 2 revisions

Trinidad serves static files from your public folder (configurable as public: in trinidad.yml defaults to 'public') that is expected to live relative to your application root directory. However you're still able to mount arbitrary (shared) file-system directories as if they were sym-linked from the public directory :

---
  public: 
    root: public # same as the above "public: public" setting
    aliases: # allows to "link" other directories into the public root e.g. :
      /home: /var/local/www # available under http://my-host.org/home
      /static: /var/local/www/shared/static # http://my-host.org/static

Trinidad will use the default servlet to serve files under your public directory. The performance of serving static content is comparable to httpd thus this most likely should not be a reason to proxy Trinidad e.g. with Apache. You can even get better performance esp. for "small" asset files since they might be cached in memory if you hand tune the "public" cache (please note that the cache is shared for all static files that are being served by your application, including sendfile) settings based on the size and amount of your assets :

---
  public: 
    #root: public
    #cached: true # enable (in-memory) asset caching on for env != 'development'
    cache_ttl: 60000 # cache TTL - 1 minute (60 * 1000)
    cache_max_size: 20480 # max cache size - 20MB (20 * 1024 kB)
    cache_object_max_size: 1024 # max cache object (asset) size 1MB (1024 kB)

Asset Pipeline

Since Rails 3.1+ you might have run into the asset pipeline which is a great tool to boost your development experience (since these days it's all about those JavaScripts). However it's not such a great idea to be used on production. We recommend pre-compiling your assets instead using the Rails provided rake assets:precompile RAILS_ENV=production task and disabling the Rails asset server e.g. sample environments/production.rb snippet :

  # Disable Rails's static asset server (Trinidad will server those)
  config.serve_static_assets = false
  # Compress JavaScripts and CSS
  config.assets.compress = true
  # Don't fallback to assets pipeline if a precompiled asset is missed
  config.assets.compile = false # should not happen if you pre-compile
  # Generate digests for assets URLs
  config.assets.digest = true
  # Defaults to Rails.root.join("public/assets")
  # config.assets.manifest = YOUR_PATH

Do not forget to un-comment the Bundler.require(*Rails.groups(:assets => %w(development test))) line in your application.rb since you won't need your asset dependencies to be loaded with your application ...

Temporary Fix for 1.4.x

NOTE: due internal (Tomcat) changes, latest of Trinidad 1.4 might not serve public assets as expected. We did not decide what the best approach would be to "fix" this for Rack/Rails applications, but there's an option to configure that will work with Rails (and most Rack) applications when sub-folders are used for storing (pre-compiled) static files public/assets. The following explicit configuration will work :

  # ...
  default_servlet:
    mapping:
      - /assets/*
    #init_params:
    #  debug: 1
Something went wrong with that request. Please try again.