0

I have a resources web app, which only has static content, such as images, CSS and JavaScript.

I'm using these resources in another web app within JSF pages, but for some reason the JavaScript files are not loaded properly. I've seen two outcomes so far, either the JSF page renders weirdly (missing most of the content) or the page looks fine, but the JavaScript is not functional. CSS and images come alright.

I'm loading the resources like below

<head>
    <link rel="stylesheet" type="text/css" href="http://localhost:8080/resources/css/styles.css" />
    <script type="text/javascript" src="http://localhost:8080/resources/js/utils.js" />
</head>

FireBug shows that everything is loaded properly. The JavaScripts work fine when they are inline inside the JSF page.

I've tried with Jetty 8 and GlassFish 3, but results are pretty much same. Anyone got some pointers on what's the problem?

1 Answer 1

2

Self-closing <script> tag is not valid in HTML documents with text/html content type and the browser behaviour is undetermined. You need to close it with another tag:

<script type="text/javascript" src="http://localhost:8080/resources/js/utils.js"></script>

It's however valid in pure XHTML documents with application/xhtml+xml content type, but this is in turn not supported by IE. Serving XHTML as text/html is in turn considered harmful.

This has nothing to do with Java/JSF.

Sign up to request clarification or add additional context in comments.

8 Comments

Thanks for the swift answer. I tried with the closing tags but that didn't help. When I look at the page source with the browser, it's changed back to self-closing tag. Even the attribute order is changed. I tried it on Jetty and GlassFish with both IE8 and FF8.
What view technology are you using? The legacy JSPX has this irky behaviour. You'd need to add a comment <!-- --> between the tags. Or, better, dump it altogether and go for its awesome successor Facelets.
Adding a comment between the tags didn't help. I guess I'll have to take a look facelets then. Thanks for the help.
What view technology are you using? Is it indeed JSPX? Try <jsp:text/> instead of the comment. The comment seems to fail on some servletcontainers. See also related question: stackoverflow.com/questions/2058649/…
I misunderstood your previous comment and tried to add the comment block between the <link stylesheet/> and <script /> tags. After reading the related question, I realized you meant to add it inside the <script> tag. Well that did the job. Thanks a lot, I really appreciate it.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.