Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Scott Paterson
Scott Paterson
26,869 Points

Flexislider help

Hi guys i have a flexislider installed on my site and the way it was on the template was the following code below was to be put in my head section.

<!-- Place somewhere in the <head> of your document --> <link rel="stylesheet" href="flexslider.css" type="text/css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> <script src="http://homecook-stirling.co.uk/jquery.flexslider.js"></script>

<!-- Place in the <head>, after the three links --> <script type="text/javascript" > $(window).load(function() { $('.flexslider').flexslider(); }); </script>

it all works fine and dandy no problems my question is, Is that the right place to put the code? i am sure i've seen videos about javascript going to bottom of the page?

i have something on codepen and the code is between line 12 to 23 in html

http://codepen.io/scotty_paterson/pen/qEopu

2 Answers

Justin Dawson
Justin Dawson
4,608 Points

Its recommended to place your JavaScript at the bottom of your page to help with page load times.

Basically this means that your page will appear to load faster to the visitor since it will load all your JavaScript files last. For example if you place your jQuery library in the head of your site the browser will first load this and then move onto the content.

So, when it really comes down to it, it is just best practice for a better user experience.

In the case for FlexSlide, they use jQueries (window).load function which will ensure that this specific function does not run until the entire page is done loading and in turn means it does not matter where you place it.

Hope that helps.

Scott Paterson
Scott Paterson
26,869 Points

Thanks Justin you have been a great help just trying to get into good practice, i moved all the code to the bottom of the page and it is working fine.

i really should make a start on interactive course and learn more on this.