0

I am trying to include jquery.js and javascript.js files on my page, as proposed in the previous question by passing it through the Servlet class like:

 response.getDocument().body().appendChild(new DataNode("<script src=\"" + themeUri
                + "/js/nativeinit.js\" type=\"text/javascript\"></script>",""));

        response.getDocument().body().appendChild(new DataNode("<script src=\"" + themeUri
                + "/js/jquery.min.js\" type=\"text/javascript\"></script>",""));

When I see the Console in Browser though I see the messages for both files:

Resource interpreted as Script but transferred with MIME type text/html: "http:8080/uri/js/nativeinit.js". myhost/:47

Resource interpreted as Script but transferred with MIME type text/html: "http:8080/uri/js/jquery.min.js". myhost/:47

And then:

Uncaught SyntaxError: Unexpected token <                     nativeinit.js:1
Uncaught SyntaxError: Unexpected token <                     jquery.min.js:1

What is wrong and it cannot read them as script? Why this strange message of unexpected token? What should I change/add?

Update:

I have also added in my web.xml file:

<mime-mapping>
        <extension>js</extension>
        <mime-type>application/javascript</mime-type>
    </mime-mapping>

but problem with the same message remains. I am aware of the fact that @Javascript annotation is the recommended way in vaadin 7, but I think it should work as well on the common way. I do not set Content Type in Servlet Class. I can use there only the class BootstrapPageRespone from https://vaadin.com/api/ , which does not provide the methods from ServletResponse. Otherwise I would have set it also programatically.

Community
  • 1
  • 1
arjacsoh
  • 8,932
  • 28
  • 106
  • 166

2 Answers2

0

check this question: Chrome says "Resource interpreted as script but transferred with MIME type text/plain.", what gives? - maybe when browser requests your script, it gets answer from server as text/html. Check MIME type of your server response.

Community
  • 1
  • 1
betatester07
  • 667
  • 8
  • 16
  • I have added the content-type : text/javascript in the MIME-TYPES in Tomcat Configuration but it did not solve the issue. Anyway, I have tried the same in another project and it works. Something is not going well with the way I define the files in the Servlet, I think. – arjacsoh Oct 02 '13 at 11:58
  • ok,so now when your browser requests for ex. your /js/jquery.min.js, it gets answer with content-type: text/html set in header? – betatester07 Oct 02 '13 at 12:22
  • make sure, that you dont set content-type to text/html in servlet, that process requests to your scripts – betatester07 Oct 02 '13 at 12:23
0

The recommended approach is to use the @Javascript annotation, as discussed in this article.

Charles Anthony
  • 3,155
  • 17
  • 21