forever

package module
v0.0.0-...-1018f5c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 21, 2014 License: MIT Imports: 4 Imported by: 0

README

Go-Static-Forever

Serve files that never change

Build Status

Total views

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.

Install

This package is "go-gettable", just do:

go get github.com/ant0ine/go-static-forever

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)
}

Documentation

Copyright (c) 2013 Antoine Imbert

MIT License

Analytics

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL