-1

我运行代码

package main

import (
    "fmt"
    "net/http"
)

func main() {
    http.HandleFunc("/", sroot)
    http.ListenAndServe(":8080", nil)
}

func sroot(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Welcome")
}

并且浏览器按预期显示响应:Welcome 然后,一段时间后我尝试更改输出但发现输出没有改变!因此,当我更改输出 fmt.Fprintf(w, "Welcome 123")但浏览器仍然 ouptuts时Welcome

那么这里发生了什么神奇的事情呢?

4

2 回答 2

2

By default the browser makes a GET request when navigating to the page. The browser is also going to make some decisions about the 'cachability' of the page: Has the url changed? Has the querystring changed? Has the ETAG changed? If none of these are true, the browser is most likely serving a cached version of the page.

于 2019-01-02T12:41:25.207 回答
0

You can use gin to reload your webserver.

Installation: go get github.com/codegangsta/gin

Usage: gin run filename.go

Reference: https://github.com/codegangsta/gin

于 2019-01-02T12:41:25.053 回答