Goweb – handling static resources


Working with static files

For static files such as CSS and JS in HTML pages, you need to use the following under net / HTTP package
Method to handle

1) Stripprefix function
2) Fileserver function

3) for example:
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("views/static"))))

  • /static/Will match to/static/Development path, when browser requestsindex.htmlIn the page
    style.csS file,staticThe prefix will be replaced withviews/staicAnd then goviews/static/css
    Search in directorystyle.cssfile