HTML5 using multiple Javascripts

Associate
Joined
13 Jun 2007
Posts
1,190
Location
Dorset
Hi, am finally getting round to building a new website for myself, using HTML5, Javascript, jquery and CCS.


All so far working ok.

My question is I have 3 Javascripts which are linked to on my main HTML page as follows...

<script type="text/javascript" src="javascript/modernizr-1.7.js"></script>

<script type="text/javascript" src="javascript/jquery-1.10.1.min.js"></script>

<script type="text/javascript" src="javascript/slideshow_P1.js"></script>


Whilst this does work I wondered if this is the correct way to do it.

Any advice appreciated.
 
Google hosts several js libraries:

https://developers.google.com/speed/libraries/

Code:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>

Depending on what they're used for it's good practice to put your js calls into the footer as well.

Thanks for the google tip. Will put my js calls in the footer.

Just wanted to know whether it was good practice to list my js calls as..

<script type="text/javascript" src="javascript/modernizr-1.7.js"></script>

<script type="text/javascript" src="javascript/jquery-1.10.1.min.js"></script>

<script type="text/javascript" src="javascript/slideshow_P1.js"></script>

or it should be done another way? Can you have too many js calls?

.
 
Code:
<script src="//code.jquery.com/jquery-latest.min.js"></script>
<script>window.jQuery || document.write('<script src="{{ STATIC_URL }}js/jquery-latest.min.js"><\/script>')</script>

Using the above code it will default to using an online hosted jquery and fallback to local. Can be useful in case the linked js is down for any reason.

Nice tip.

.
 
OK, I joined Google Analytics to get an UA ID.
In my account in the "tracking Info it states to put this on my page....

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-41400435-1', 'michaelwinstone.com');
ga('send', 'pageview');

</script



I was expecting to see a script similar to what has been posted above by uniQ ...

Code:
<script type="text/javascript">
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-XXXXXX-X']);
    _gaq.push(['_trackPageview']);
    _gaq.push(['_trackPageLoadTime']);

    (function() {
      var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
      ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    })();
  </script>


Have I missed something?...


.
 
Last edited:
I believe the one you linked last is an older version, so you're one is just fine.

Thanks for the confirmation. The last time I built a site was a few years ago and I used AS3/Flash so I am playing catch up as so much has changed.
 
Back
Top Bottom