FAQ
I have an html template which does nothing but include a local javascript
file and print hello. When I serve this file, I get an error in the
Javascript console, and multiple requests are made to the server. What am
I doing wrong?

http://play.golang.org/p/_E6SM9w3m6

test.js is an empty file in the same directory where the server is running.

In the Javascript console, I get:

SyntaxError: Unexpected token '<'

referencing test.js:2.

Thanks in advance for any help.

Justin

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • DisposaBoy at Oct 20, 2014 at 6:06 pm
    Look at what is being served for the path /test.js. I'm almost certain it's your HTML file because I didn't see anything serving the js file. For that have a look at http.FileServer

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Drj at Oct 20, 2014 at 6:13 pm
    This is be a working example:
    http://play.golang.org/p/jtPC4XxZ9W
    It statically serves the files in the /js/ folder. If you put the test.js
    file in the /js/ folder it should work.

    This blog entry explains it in more detail:
    http://www.alexedwards.net/blog/serving-static-sites-with-go

    -davdi

    Am Montag, 20. Oktober 2014 15:41:45 UTC+2 schrieb Justin Gullingsrud:
    I have an html template which does nothing but include a local javascript
    file and print hello. When I serve this file, I get an error in the
    Javascript console, and multiple requests are made to the server. What am
    I doing wrong?

    http://play.golang.org/p/_E6SM9w3m6

    test.js is an empty file in the same directory where the server is running.

    In the Javascript console, I get:

    SyntaxError: Unexpected token '<'

    referencing test.js:2.

    Thanks in advance for any help.

    Justin
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Justin Gullingsrud at Oct 21, 2014 at 1:46 am
    Thanks, that's a great pair of examples. In the intervening time I also
    found a solution here:

    https://github.com/mattetti/goHtmlTemplateExample/blob/master/main.go

    Cheers,
    Justin
    On Monday, October 20, 2014 2:13:28 PM UTC-4, drj wrote:

    This is be a working example:
    http://play.golang.org/p/jtPC4XxZ9W
    It statically serves the files in the /js/ folder. If you put the test.js
    file in the /js/ folder it should work.

    This blog entry explains it in more detail:
    http://www.alexedwards.net/blog/serving-static-sites-with-go

    -davdi

    Am Montag, 20. Oktober 2014 15:41:45 UTC+2 schrieb Justin Gullingsrud:
    I have an html template which does nothing but include a local javascript
    file and print hello. When I serve this file, I get an error in the
    Javascript console, and multiple requests are made to the server. What am
    I doing wrong?

    http://play.golang.org/p/_E6SM9w3m6

    test.js is an empty file in the same directory where the server is
    running.

    In the Javascript console, I get:

    SyntaxError: Unexpected token '<'

    referencing test.js:2.

    Thanks in advance for any help.

    Justin
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Nigel Tao at Oct 21, 2014 at 1:13 am

    On Tue, Oct 21, 2014 at 12:41 AM, Justin Gullingsrud wrote:
    multiple requests are made to the server.
    If you changed
    log.Println("request of type", r.Method)
    to be
    log.Printf("request of type %q for path %q", r.Method, r.URL.Path)

    Then I suspect that you'll see multiple requests because your browser
    is also requesting /favicon.ico. You may want to add this snippet to
    the top of your "/" handler:

    if r.URL.Path != "/" {
       http.Error(w, etc)
       return
    }

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedOct 20, '14 at 2:53p
activeOct 21, '14 at 1:46a
posts5
users4
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase