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.

Error when embedding jQuery as a javascript template

August 24, 2011 4:57pm

Subscribe [4]
  • #1 / Aug 24, 2011 4:57pm

    David Hemphill

    18 posts

    This question may be related to a resolved thread.

    Hi, I think that there may be a bug in EE, as I’m having the same issue on an install I’m working on.

    Suppose I place the code for jQuery 1.6.2 into a template and set its type to “javascript”. Somehow when output using a standard javascript tag the Web Inspector will throw an error saying it can’t find the jQuery object, and thus, borks all of the javascript that depends on it.

    This issue is fixed (in that the javascript still executes) by setting the template to “static”, but it will still throw the warning: “Resource interpreted as Script but transferred with MIME type text/html”.

    I’d love to help track down this issue by setting up a test environment duplicating the bug.

  • #2 / Aug 25, 2011 2:28am

    John Henry Donovan

    12339 posts

    Hi David,

    What version and build of EE are you using?
    I would recommend either linking to jQuery locally or to the CDN as opposed to creating a template specifically for it.

    In your Output and Debugging setting please confirm that debugging is set to 1 an also set to 1 in your config.php

  • #3 / Aug 25, 2011 1:55pm

    David Hemphill

    18 posts

    Thanks for responding John. The version is 2.2.2 build 20110801. Both of the debug settings are set to 1.

    Regarding linking to a local version or Google’s version, I would recommend this as well, but my client has a staging server and the easiest way for them to copy changes to the site over is by copying the templates to the new site—and they like to do that with templates, css, javascripts and all. It still seems like it shouldn’t be touching the javascript on output.

  • #4 / Aug 25, 2011 5:01pm

    David Hemphill

    18 posts

    Strangely enough: it only seems to happen on the minified version of jQuery.

  • #5 / Aug 26, 2011 2:21pm

    Lisa Wess

    20502 posts

    Hi, David,

    Are you including protect_javascript in your config.php? And also, are your PHP Errors debugging set to 1, or set to 2 in Admin > Outupt and Debugging preferences?

    Thanks!

  • #6 / Aug 26, 2011 3:41pm

    David Hemphill

    18 posts

    Thanks Lisa,

    We are not using the protect_javascript option in config.php as it defaults to “y”. Also, debugging is set to 1 in both areas.

  • #7 / Aug 26, 2011 3:47pm

    David Hemphill

    18 posts

    Just for kicks, I set protect_javscript variable explicitly to “y” in config.php, but it didn’t change anything.

  • #8 / Aug 26, 2011 3:50pm

    David Hemphill

    18 posts

    I should also note: this seems to affect jQuery UI’s minified version too, when it’s set to “javascript”. Changing it to “static” works fine (except for the warning thrown in the console).

  • #9 / Aug 28, 2011 6:06pm

    Kevin Smith

    4784 posts

    Regarding linking to a local version or Google’s version, I would recommend this as well, but my client has a staging server and the easiest way for them to copy changes to the site over is by copying the templates to the new site—and they like to do that with templates, css, javascripts and all. It still seems like it shouldn’t be touching the javascript on output.

    For HTML and CSS templates, this isn’t an issue, but I wouldn’t recommend including jQuery as a template in your EE setup precisely because of the effects it’s having here. jQuery really would be better handled by serving up a static file outside of EE or using a CDN. Is there a reason why your client would need jQuery itself to be in a template? It isn’t a file that should require very much maintenance or updating. And if they really need to update to a more recent version, you could link to Google’s CDN within a header embed and simple update that reference to the whichever jQuery version you desire.

  • #10 / Aug 28, 2011 10:51pm

    David Hemphill

    18 posts

    Thanks for the response Kevin. The reason is primarily about feature development. They use a staging server with a clone of the production database, and they like developers to use that while working on new features or implementing new designs for testing and approval, instead of the live site. They find copying the whole template folder over to the production site eases their workflow.

    The only other reason they cited was some of their users have software that blocks javascript files that don’t come from their domain (which is why they stopped using Google’s CDN).

    I understand the recommendation is to use Google’s CDN or host your own version outside of EE, but my ultimate questions are: Will this affect other scripts that are minified? Is it only safe/supported to host small javascripts with the built-in template functionality?

  • #11 / Aug 29, 2011 4:35pm

    Kevin Smith

    4784 posts

    I’m going to ask the devs for a better explanation than the one I’m about to give, but while we wait for the answer, here’s how I would approach it: putting JS in templates is technically supported, but right now it looks like there are some edge cases when it’s not reliable. What’s causing that unreliability, I’m not sure, but if I were to run up against these issues, my solution would be to serve a local copy of jQuery (minified) from an actual file outside EE rather than inside a template.

    Hang tight for me while I get some input from the devs.

  • #12 / Aug 31, 2011 4:04am

    John Henry Donovan

    12339 posts

    David,

    By way of an update, our dev has been delving into this so thanks for your patience.

  • #13 / Aug 31, 2011 6:10pm

    David Hemphill

    18 posts

    Thank you, John and Kevin. I’ll hang tight why you do your thing 😊.

  • #14 / Aug 31, 2011 6:42pm

    Kevin Smith

    4784 posts

    Alright, so I’ve got about a halfway update for you here: we’ve discovered the problem, just not the solution. At least not yet anyway.

    The minified jQuery file contains a bit of code that looks an awful lot like an EE tag:

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

    That’s what’s causing you issues. Now to fix it, we’ve got to find a way to still allow embeds within a javascript template without this happening. Stay tuned, and we’ll get you an update soon…

  • #15 / Sep 01, 2011 9:35am

    Kevin Smith

    4784 posts

    Hey David,

    Just got another update from our dev team. It looks like the actual fix for this will take some time and be more involved than I originally expected. We’re actively working on this and going to try to get a fix for this included in the next release, but in the meantime, the recommendation is to change your template type to “static”.

    Does that take care of the issues for now?

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

ExpressionEngine News!

#eecms, #events, #releases