Static Files

Pragmatic, automatic, let's get static

Serving static files has been removed from Raze core in the latest release. It may be re-introduced as a separate package that is implemented via middleware.
The rest of the page is for older versions of Raze.

First and foremost, Raze assumes that your static folder is, well, static. This means that by default, it assumes that your static directory is unchanging. With this assumption, some major optimizations can be made.

If you want to add or remove files in the static directory during runtime, this is possible and easy to enable (while still achieving Raze's optimizations). Read the Dynamic Static-Directories section below.

Accessing Static Files

By default, static files are served from the static directory. The word static is excluded from the path. So if you have a file named styles.css in a stylesheets folder in the static directory like so:

my_app
│
├— src
│
├— static
  │
  ├— stylesheets
    │
    ├— styles.css

...then to fetch that file, you would would hit http://localhost:7777/stylesheets/styles.css

Changing the Static Directory Path

The static directory can be changed via the Raze.config.static_dir property.

Raze.config.static_dir = "./public"

Dynamic Static-Directories

Dynamic - characterized by constant change, activity, or progress Static - lacking in movement, action, or change Oxymoron - a figure of speech in which contradictory terms appear in conjunction

For Raze to recognize file additions or deletions in the static directory, you need to specify a subset of the static directory to match against the path.

For example, if you know that you will add and/or remove images in the ./static/images directory, you would let Raze know like so:

Raze.config.dynamic_static_paths << "/images"

So any paths that start with /images (e.g. /images/users/user1234/profile.png), Raze now knows to at least check if it is an existing static asset. Otherwise, Raze will rely on the static indexing that it does on startup.

Disabling Static Indexing

Disabling static indexing can slow down non-static routes by 20%. It is recommended to instead add paths to `dynamic_static_paths` as shown above if performance is a priority.

Static indexing is where Raze will remember the paths to all of the static assets on startup for quicker file serving. If static indexing is disabled, then for each and every request, Raze will perform an IO operation to check if the path is a reference to a static asset.

To disable static indexing, do:

Raze.config.static_indexing = false

The above is the same as doing the following:

Raze.config.dynamic_static_paths << "/"