For serving directories of static assets, Revel provides the static built in module, which contains a single Static controller. Static.Serve action takes two parameters:

Config

The static module is optional and is enabled by default.

By default when you create a new project the following configuration options are set in the app.conf file:

module.static = github.com/revel/modules/static

Additionally, these will be set in routes conf/routes:

	GET    /public/*filepath            Static.Serve("public")
	GET    /favicon.ico                 Static.Serve("public","img/favicon.png")

As defined in the route manual the syntax used for defining a route is Controller.Action(prefix,filepath). So the word public has nothing to do with visibility, it follows the default directory organization

  • prefix (string) - A (relative or absolute) path to the asset root.
  • filepath (string) - A relative path that specifies the requested file.

Bad example

GET    /img/icon.png                Static.Serve("public", "img/icon.png") << space causes error
Important:
For the two parameters version of Static.Serve, blank spaces are not allowed between " and , due to how encoding/csv works.
Static content can only be served from within the application root for security reasons. To include `external assets` consider symbolic links or a git submodule

Best Practices

Although Revel does serve out static content in the most efficient way it can, it makes more sense for your web server to serve the static files directly.