////
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
////

Since version 3, Grails integrates with the https://github.com/wondrify/asset-pipeline[Asset Pipeline plugin] to provide sophisticated static asset management. This plugin is installed by default in new Grails applications.

The basic way to include a link to a static asset in your application is to use the link:{gspTagsRef}resource.html[resource] tag. This simple approach creates a URI pointing to the file.

However, modern applications with dependencies on multiple JavaScript and CSS libraries and frameworks (as well as dependencies on multiple Grails plugins) require something more powerful.

The issues that the Asset-Pipeline plugin tackles are:

* Reduced Dependence - The plugin has compression, minification, and cache-digests built in.
* Easy Debugging - Makes for easy debugging by keeping files separate in development mode.
* Asset Bundling using require http://asset-pipeline.com/manual/index.html#directives[directives].
* Web application performance tuning is difficult.
* The need for a standard way to expose static assets in plugins and applications.
* The need for extensible processing to make languages like LESS or Coffee first class citizens.

The asset-pipeline allows you to define your javascript or css requirements right at the top of the file, and they get compiled on War creation.

Take a look at the http://asset-pipeline.com/manual[documentation] for the asset-pipeline to get started.

If you do not want to use the Asset-Pipeline plugin, you can serve the static assets from directories `src/main/resources/public` or `src/main/webapp`, but the latter one only gets included in WAR packaging but not in JAR packaging.

For example, if you had a file stored at `/src/main/resources/public/images/example.jpg` and your Grails application was running on port 8080, then you could access the file by navigating to http://localhost:8080/static/images/example.jpg[http://localhost:8080/static/images/example.jpg].

==== Cache Configuration for Static Resources

By default, files under `src/main/resources/public` or `src/main/webapp` are served with an HTTP response header of `Cache-Control: no-store`.
To have them be cached by the browser, you can set the configuration setting `grails.resources.cachePeriod: number` in `application.yml` so that they are served with a response header of `Cache-Control: max-age=number` indicating to the browser how many seconds the file should be considered fresh.
