13

Go: HTML can not find the css file

 3 years ago
source link: https://www.codesd.com/item/go-html-can-not-find-the-css-file.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Go: HTML can not find the css file

advertisements

So i'm writing a web application in Golang. The html references a css file like so: <link href="/css/index.css"..., but the css file is never found!.

Here is the bummer though, i have a couple of css files and they are all in the same folder, and they all work!.

If i create another css file and name it index2.css and copy the contents of index.css into index2.css, this works perfectly, but for some reason, the name index.css does not work!

Also, when i go to the link http://localhost:8080/css/ this list all my css files. If i click on any of them, it opens up perfectly except index.css; i get a 404 not found.

This is really strange, any idea what could be the problem?

All files in css folder:

index.css not found:

<head>
    <title>Title</title>
    <link href="/css/index2.css" rel="stylesheet" type="text/css" media="screen"/>
    <link rel="icon" type="image/png" href="/images/img.png"/>
    <script src="/scripts/jquery.min.js"></script>
    <script src="/scripts/scroll.js"></script>
</head>

When i like to <link href="/css/index2.css" rel="stylesheet"... i can see the css style on my page. When i link to <link href="/css/index.css" rel="stylesheet"... i can't.

index.css exists in my folder:

It works now. I think it was a permission issue. I deleted the old index.css and created a new one and it works now. Thanks for the help.


Did you mark the css folder as static in your server side script? Try running this code from your go web server and see if you could access those css files.

package main

import (
    "net/http"
)

func main() {
    http.Handle("/", http.FileServer(http.Dir("./web/content/css")))
    http.ListenAndServe(":8080", nil)
}

I'm not sure if I got your folder structure right, you might have to modify "./web/content/css".


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK