ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Syntax errors on javascript saved as EE templates

February 20, 2011 5:15pm

Subscribe [4]
  • #1 / Feb 20, 2011 5:15pm

    Lee Powell

    88 posts

    Hi,

    I moved all my external javascript files into EE template files for optimisation. And now, my javascript keeps breaking due to syntax errors of the outputted javascript.

    Does the system do something to the javascript? rewrite it in some way? or parse it? Because my files are identical.

    The only way I’m making the errors to go away is to move them back as external files.


    Thanks

  • #2 / Feb 20, 2011 5:33pm

    grrramps

    2219 posts

    Did you set the template up as a Javascript template?

    FWIW, I’ve found some Javascript that just doesn’t work in EE’s templates. Ever. It’s not often, but there are some.

  • #3 / Feb 20, 2011 5:39pm

    Lee Powell

    88 posts

    Yes I did.

    This is pretty much every file is failing. Especially on minified javascript.

  • #4 / Feb 20, 2011 5:55pm

    grrramps

    2219 posts

    This is pretty much every file is failing. Especially on minified javascript.

    I’ve had more trouble with minified Javascript, too. Have you tried setting the template back to plain text? And, how it it failing? Javascript errors in the console? Or, the script just isn’t working? Are you calling the script in the header as an embed? Or, embedding the script somewhere? Double check the path, too.

  • #5 / Feb 21, 2011 9:58am

    Sue Crocker

    26054 posts

    Thanks for the assist, Ron.

    Lee - I’d really consider using an external .js file. How often are you going to be editing a minified js script?

  • #6 / Feb 21, 2011 10:15am

    Lee Powell

    88 posts

    I’ve tried setting it as static, webpage and javascript. All fail. I’m including using {path=javascript/jquery_145}. It’s failing by causing symtax errors - which in turn causes all my other javascript to stop. Paths are all fine.

    Thanks Sue - but that’s not really the point. I was hoping to keep them all in EE for consistency, optimisation etc. If EE had the option - surely it should work?

    I’m just finishing my first EE build and this was some of the final bits to do. Sadly there are still so many bugs in EE.

  • #7 / Feb 21, 2011 2:00pm

    Rob Sanchez

    335 posts

    If you have your Debug Preference set to 0: No PHP/SQL error messages generated, your Javascript can get hosed.

  • #8 / Feb 21, 2011 2:59pm

    Lee Powell

    88 posts

    Thanks for the heads up. Oddly, setting the file type to ‘static’ and settings Debug to 1, seems to sort the problem. However, this is a workaround, and not a solution.

    What is EE doing to the javascript files anyway?

    Why not just serve them straight to the page?

  • #9 / Feb 21, 2011 3:23pm

    Lee Powell

    88 posts

    OK - looking at the differences between static and javascript, is that static does not go through EE’s parsing engine. So, there’s something funky going on when the templates are being parsed.

  • #10 / Feb 21, 2011 3:33pm

    Lee Powell

    88 posts

    Just did a diff on what’s being spat out from EE, and a native jQuery file, and the result was interesting. In the native code, this following code exits:

    noData:{embed:!0,object:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",applet:!0},hasData:

    However, the javascript file resulting from EE parsing it produces this:

    noData:,hasData:

    As you can see, noData, has, urm, no data…

    This can be fixed, by adding a white space before, and after the brackets:

    noData: { embed:!0,object:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",applet:!0},hasData:

    But this really isn’t ideal to have to do diff’s on all my javascript files to debug each one.

  • #11 / Feb 21, 2011 3:38pm

    Lee Powell

    88 posts

    Looking at this, do you think the section ‘{embed’ is attempting to be parsed by EE? and embed a template, thus breaking the js.

  • #12 / Feb 22, 2011 8:06am

    Sue Crocker

    26054 posts

    It could be.. but again, if you are wanting to just store javascript in an EE template, static is probably going to work better for you just in case that’s the problem.

  • #13 / Feb 22, 2011 8:33am

    Lee Powell

    88 posts

    Thanks Sue - I’m fairly convinced this was the problem, and was an unfortunate coinsidence it contained the {embed code which caused the issue. All is working now.

  • #14 / Feb 22, 2011 4:53pm

    Ingmar

    29245 posts

    Excellent. Please don’t hesitate to post again as needed.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases