Documentation ¶
Overview ¶
Serve files that never change
If you can put a version string (commitish for instance) in the path of your static files, then the content served by the corresponding URLs is guaranteed to never change. A whole set of optimisations become possible.
* If the request contains `If-Modified-Since`, return `304` without checking anything
* Set the `Expires` to `<forever>` (`<forever>` defaulting to one year)
* Set the `Cache-Control` header to `public; max-age=<forever>; s-maxage=<forever>`
* Set the `Last-Modified` headers to `<origin>` (`<origin>` being 1970)
This handler is implemented as a wrapper around http.FileServer, and when the isDevelopment flag is set, http.FileServer is used directly.
Example:
package main import( "github.com/ant0ine/go-static-forever" "net/http" ) func main() { handler := forever.NewStaticHandler( http.Dir("/static/"), // FileSytem to serve "1234567", // version string, like a commitish for instance nil, // "forever duration", defaults to one year false, // isDevelopement ) http.ListenAndServe(":8080", handler) }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewStaticHandler ¶
func NewStaticHandler( root http.FileSystem, version string, foreverDuration *time.Duration, isDevelopment bool) http.Handler
foreverDuration defaults to one year.
Types ¶
This section is empty.