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.

bug with linking to javascript files?

September 22, 2011 4:33pm

Subscribe [4]
  • #1 / Sep 22, 2011 4:33pm

    tunnel7

    125 posts

    Hello.  I’m working on a project and I’m running EE 2.2.2 ... just had a heck of a time getting javascript pulled into my template.  I tried all the following methods:

    src=”{path='inc/slides.behavior'}” (attempting to link to file in template group named /inc) 
    src=”/inc/slides.behavior” (attempting to link to file in template group named /inc)
    src=”/js/slides.behavior.js” (created new directory at root for /js)
    src=”/images/javascript/slides.behavior.js” (created new directory inside existing images directory)

    The only one that worked was the last one.  From my understanding the first one should have worked as well (well, really they all should have).  Is there a bug in 2.2.2 with calls to javascript?  What is the best practice for linking to js files?  Ideally, I’d love for the first option to work (have the js in the default templates.

    Any thoughts greatly appreciated.  I am up and running using the last version but for future projects would love to get others thoughts.

  • #2 / Sep 22, 2011 5:51pm

    glenndavisgroup

    436 posts

    Hi tunnel7,

    I think this is the reason why it’s not working:

    1) http://yourdomain.com/images/javascript/slides.behavior.js => here the file extension is “.js” which is a valid one and the server knows what to do with the file. The request gets passed to the index.php to render it. To test it change the domain in the URL to yours and copy and past the line in your browser you will see that it works.

    2) As for http://yourdomain.com/inc/slides.behavior => here the file extension becomes “.behavior” and the server doesn’t know what to do with it. You can see this by changing the domain name in the URL to yours and copy and paste it in your browser. You’ll see nothing gets returned to the browser. This is because the server doesn’t know what mime type “.behavior” is and stops the request.

    The only way it will work is if you pass the request directly to “index.php” like this:

    http://yourdomain.com/index.php/inc/slides.behavior

    The only other way to make it work with your code is to change the file name to “slides_behavior” this will work because the server now thinks it’s a folder and passes the request to the index.php which will know how to render it.

    I hope I explained this correctly. If anyone from EE can verify this.

    Mike

  • #3 / Sep 23, 2011 9:10am

    Sue Crocker

    26054 posts

    Sounds correct to me, Mike. Thanks for the assist.

    tunnel7 - as far as a best practice goes, I prefer to keep .css and .js files outside of EE. But that’s a personal preference.

  • #4 / Sep 23, 2011 9:24am

    tunnel7

    125 posts

    Thanks for the feedback, Mike.  That all makes sense and thanks Sue for best practices ... We’ve been going the route of keeping files outside of EE ... I keep wanting them to be a part of template groups but I can see that would present potential security risks.  Thanks for clarifying.

  • #5 / Sep 23, 2011 10:58am

    Mark Bowen

    12637 posts

    Hi tunnel7,

    Just wanted to see if you’re all set now? Is it okay to close this thread?

    Thanks,

    Mark

  • #6 / Sep 23, 2011 11:10am

    tunnel7

    125 posts

    Sure.  I more just wanted to make sure I wasn’t missing something obvious ... this thread has clarified things for me.

  • #7 / Sep 23, 2011 12:10pm

    Mark Bowen

    12637 posts

    Many thanks.

    I’ll close this one out for now then.

    If anything else crops up then please don’t hesitate to post again as needed.

    Cheers,

    Mark

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

ExpressionEngine News!

#eecms, #events, #releases