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.

Javascript template types

April 05, 2012 5:55pm

Subscribe [2]
  • #1 / Apr 05, 2012 5:55pm

    james Brown

    492 posts

    I know that EE has a javascript template type. What is the advantage vs disadvantage of using the EE javascript template type as opposed to just storing it in the file system. Are there any performance advantages to either method?

  • #2 / Apr 06, 2012 2:47pm

    Robin Sowell

    13255 posts

    Hi james Brown.  (Heh- always wanted to say that.)

    The biggest advantage is that you can include EE variables in a js type template and they’ll parse.  So if you need to do that?  A template is the way to go.

    If you don’t, I generally prefer to develop w/it in the template and move it to a file on release- because I do all of my editing via the CP.  (Some folks prefer to use files and ‘save templates as files’- which would make that moot.)

    If there’s no need to parse the template, there’s no sense in adding the overhead.  You could use a static type (or the smart_static_parsing hidden config), but I just prefer to have a js file.  I do pretty much the same with my css.  That said?  The performance benefit is tiny to the point I doubt it’s measurable.  I just personally like linking to the files (and I do not like inline js if I can avoid it- which isn’t necessary if you’re putting it in a template, but some folks just embed the js rather than linking to it- which I don’t like).

    And now I have rambled.  You get a slight benefit from linking to a js file vs. having the js in a template (particularly if you are parsing the template).  If you NEED to have it parsed in order to include dynamic content?  Certainly don’t worry about doing so.  But if you don’t need it parsed and it’s purely static… it’s really up to you and your work flow.  But I personally go with files, since I prefer that format and it is the leanest performance wise.  Even if I won’t notice any difference.

    That clarify at all?

  • #3 / Apr 06, 2012 2:54pm

    RedSeal

    7 posts

    Yes, definitely. That is kinda what I had assumed. But I didn’t know if there was some benefit to having it in the CP that I wasn’t thinking of. Thank you.

  • #4 / Apr 06, 2012 4:15pm

    Robin Sowell

    13255 posts

    You assumed right.  About the only time you need it in an EE template is when you need some EE variables in there making things dynamic.  I HAVE done that before.  But most times that’s not the case.  In which case- I just link to the file.  Though mileage does vary.

    (I have seen folks dump jquery in a template and then embed it.  And just- no.  Don’t do that.  If for no other reason than view the source of the resulting page!)

    If you run into any other conundrums, just give us a yell!

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

ExpressionEngine News!

#eecms, #events, #releases