go_gzip

package module
v0.0.0-...-53041e1 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2019 License: MIT Imports: 10 Imported by: 0

README

go-gzip

A go helper to serve gzipped static contents in website server. This require the use of Julien Scmidt's router

Gzip static contents (mainly css & js) can speed up page loading time by a lot. Read the detail here

This go-gzip is, in essence, a Julien Schmidt's router handler which serve static contents

At this moment, only .js and .css files will be gzipped

Installation

go get -u github.com/albertsundjaja/go-gzip

How to use

This is how to serve files normally in httprouter
router := httprouter.New()
// with the httprouter, this is how you serve static contents normally
router.ServeFiles("/rsc/static/*filepath", http.Dir("resource/"))
With go-gzip
import (
  goGzip "github.com/albertsundjaja/go-gzip"
)

func main() {
  router := httprouter.New()

  // create new handler
  staticHandler := goGzip.CreateNew()
  // this is the location of the parent folder of the resources
  staticHandler.ResourceFolder = "resource"
  // this will create and rewrite a .gzip version of all .css and .js
  // CAUTION: if you skip this, then the original version will be served
  staticHandler.ProcessResourceFolder()

  router.GET("/rsc/static/*filepath", staticHandler.StaticFilesHandler)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateNew

func CreateNew() goGzip

constructor

Types

This section is empty.

Jump to

Keyboard shortcuts

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