W
W
WoWtchik2014-12-09 01:30:52
go
WoWtchik, 2014-12-09 01:30:52

How to prepare a Go server for page caching?

We needed a simple web server, a little customizable, like HTTPSimpleServer in python, only compiled into a binary. The choice fell on Go. Everything is fine, but it does not allow you to use page caching using the manifest.
Chromium throws
Application Cache Progress event (0 of 2) localhost:10000/index.html
Application Cache Error event: Resource fetch failed (4) localhost:10000/index.html
The whole server is essentially
http.Handle("/", http. StripPrefix("/", http.FileServer(http.Dir("."))))
if err := http.ListenAndServe(":10000", nil); err != nil {
log. Fatal("ListenAndServe: ", err)
}
CACHE
MANIFEST
CACHE:
index.
I run python -m SimpleHTTPServer 10000.
Everything is cached. But you need to make Go work.
How?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
SilentFl, 2014-12-09
@SilentFl

Good question =)
For Go query like "/" and "index.html" are the same thing, but for caching they are different things.
Specify "/" instead of "index.html", and you will be happy.

W
WoWtchik, 2015-01-02
@WoWtchik

As it turned out, everything was simple there:
you just had to remove index.html from the manifest. In most browsers that support the technology, the page that declares the use of manifests is cached anyway.
PS (Offtop):
If the page contains via xmlhttprequest (or ajax), they should be specified in the manifest, for example in the Internet section (if they should not be cached), even if there is no request for a specific document, for example:

request = $.ajax({url : "./getBook/",
                          type : "GET",
                          timeout : 500,
                          success : syncPagesCarring(dt)});

in the manifest will look like:
INTERNET:
./getBook

without specifying in the manifest, there will be no caching (at least in chromium v39), and all requests even with an available server from the cached page will be sent
to the grandfather's village.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question