This question already has an answer here:
I'm using Go to build a website. When serving in static files, css and js, no matter what I do the updates to files will not show. I've tried cache busting, deleting cache in my web browser, and deleting the disk cache on my computer, but no matter what ( even across different browsers ) an old version of the file is served. I've looked all over an found no answers.
To illustrate, I have a file main.css
html {
text-align:center;
}
However, the following css ( from an older file ) shows up in browser
html {
background-color:red;
}
Chrome's Developer Tools saying the css is loading in with a status of 200.
My Questions:
1) What is going on?
2) How do I fix this issue?
My code is as follows: test.go package main
import (
"html/template"
"log"
"net/http"
)
type PageVariables struct {
Name string
}
func main() {
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
http.HandleFunc("/", HomePage)
log.Fatal(http.ListenAndServe(":8000", nil))
}
func HomePage(w http.ResponseWriter, r *http.Request){
HomePageVars := PageVariables{ //store the date and time in a struct
Name: "PDiddy",
}
t, err := template.ParseFiles("homepage.html") //parse the html file homepage.html
if err != nil { // if there is an error
log.Print("template parsing error: ", err) // log it
}
err = t.Execute(w, HomePageVars) //execute the template and pass it the HomePageVars struct to fill in the gaps
if err != nil { // if there is an error
log.Print("template executing error: ", err) //log it
}
}
homepage.html
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="./static/css/main.css">
</head>
<body>
<div class="container-fluid">
<div class="jumbotron">
<div class="row">
<h1>Welcome to HQ {{.Name}}</h1>
<div class="col-sm-4">
<h2>Here's Whats Happening</h2>
</div>
<div class="col-sm-8">
<h2>Select A Company</h2>
</div>
</div>
</div>
</div>
</body>
</html>
</div>