1

I have two pages serving up the exact same static page. I get an error on the second page, but I can’t figure out why.

No error: jatecson.com/information

Error: jatecson.com/set/images

I get this error in Chrome: “Uncaught SyntaxError: Unexpected token <”

In Safari I get another error: Did not parse stylesheet at ‘jatecson.com/set/css/main.css’ because non CSS MIME types are not allowed in strict mode.

Clicking on the error in the console takes me to line 1 of the web page:

Can anyone offer a suggestion on how to fix this?

I’m running EE 2.10.1.

1 Answer 1

1

... My friend, did you check your resources? You are getting an error on the second page because you are accessing your Main.js from relative paths in your template.

jatecson.com/information : http://jatecson.com/js/Main.js

Load that file and yay! We've loaded your JavaScript file.

jatecson.com/set/images : http://jatecson.com/set/js/Main.js

Load that file ... and... hrmmm. That doesn't seem right...

You must be loading resources with a relative path in that template, when you should be using the {site_url} variable to direct your resources to absolute paths.

Here is your code to load that JavaScript file:

<script type="text/javascript" src="js/Main.js"></script>

You are loading from a relative path! So when your URI is / (base site root), you get http://jatecson.com/js/Main.js. But when your URI is /set/, you're getting http://jatecson.com/set/js/Main.js. This is true of all of your resource tags. If these are ExpressionEngine parsed templates, you should use the {site_url} path like so:

<script type="text/javascript" src="{site_url}js/Main.js"></script>

You might need to add a / after {site_url}, depending on what it's set at.

If these aren't ExpressionEngine templates and actual flat static served files, you'll need to edit them and manually add your domain to those src parameters.

1
  • This would be my guess too. You are getting a parse failure for main.css because it contains a '<'. If gets a '<' in it because it if not returning a CSS file, but an HTML formatted error page. Nov 1, 2015 at 7:50

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.