Microsoft CDN

Microsoft CDN

allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
edited February 2012 in Announcements
Hello all,

I'm delighted to say that Microsoft have offered to host DataTables on their CDN! I have a blog host here with further information: http://datatables.net/blog/Microsoft_CDN .

Basically all you need to do to use DataTables from the Microsoft CDN is:

[code]



[/code]

Then initialise DataTables as you normally would. Couldn't be simpler :-)

I've put together a (intentionally) very simple demo page, showing nothing but a static HTML file loaded from DataTables.net, and DataTables being loaded from the CDN: http://datatables.net/media/blog/cdn/ . The only CSS used on the page is provided by the CDN, so there is only styling on the DataTable, and doesn't effect the rest of the page (which would be using your own stylesheets).

Thank you to Microsoft for hosting DataTables on their CDN!

Regards,
Allan

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    edited February 2012
    DataTables 1.9.0 is now also available on the CDN.

    For a full list of the available files see:
    http://www.asp.net/ajaxLibrary/CDNjQueryDataTables190.ashx

    To include the DataTables main file:
    [code][/code]

    Regards,
    Allan
  • urosbeurosbe Posts: 2Questions: 0Answers: 0
    I would like to know what is the best way to use local copy "fall back" just in case CDN is not available at the moment of loading?

    Similar example for jQuery:
    if (typeof jQuery === 'undefined') document.write("<\/script>")
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    That looks like a sensible approach to me. SCRIPT tags are executed in sequence, so that seems like as good a approach as any.

    Allan
  • blagblag Posts: 18Questions: 0Answers: 0
    Allan

    Good to see that v1.9 is on the Microsoft CDN...
    But, I though that I might take the opportunity to point out that the link you provided
    [quote] http://www.asp.net/ajaxLibrary/CDNjQueryDataTables190.ashx [/quote]
    is NOT the script - if the script for v1.9 is to be used from Microsoft's CDN as per your original post on this topic on January 25, this is the code:
    [code][/code] (or similar, depending on whether you wish to use the minified version or not) whereas including the link ending in '.ashx' as follows:
    [code][/code] throws errors - OF COURSE!
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Heh - good point! Thanks for pointing that out. I've updated me comment above to save any confusion in future. I'm also going to post instructions on how to use the CDN on the download page soon :-)

    Regards,
    Allan
  • patriklindstrompatriklindstrom Posts: 15Questions: 0Answers: 0
    edited February 2012
    I tried the following fail back:
    [code]


    if (typeof jQuery.fn.dataTable == 'undefined')
    document.write(unescape("%3Cscript src='/Scripts/jquery.dataTables.min.js'" + "type='text/javascript'%3E%3C/script%3E"));

    [/code]
    Wich worked fine.

    I did some measurement but it was faster with the localstorage then the CDN. Maybee I should add some Etags or something. Or is the Microsoft CDN slow?

    It seemed that the google CDN for jQuery was faster then the asp.net for jQuery. I am using Firebug to measure it. With and without cache.

    My web app is a intranet application that is used a lot by its inhouse business users. So of course its better with CDN for a internet applikation.
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Rather than checking for jQuery undefined, you probably want to do:

    [code]
    if (typeof jQuery.fn.dataTable == 'undefined')
    [/code]

    since that then checks for DataTables.

    > I did some measurement but it was faster with the localstorage then the CDN.

    You note further on that it is an Intranet application you are working on, so your local file is presumably coming from a local server, which is going to be _much_ faster than any CDN since there are less hops to the server.

    One of the key things about the CDN is that it allows sharing of the same file across sites. So if www.a.com uses DataTables and so does www.b.com, then the browser only has to download it once. It also makes trying out DataTables nice and easy since you don't need to install anything on your own server.

    So like everything else, there are pros and cons to each approach. Sometimes using the CDN version will be the right thing to do, sometimes your own local copy will be.

    Allan
  • patriklindstrompatriklindstrom Posts: 15Questions: 0Answers: 0
    >you probably want to do
    Yes you are correct Allan I pasted a mismatch of code. I was testing MS jQuery CDN and Googles at the same time for jQuery. I corrected it. About the microsoft ajax CDN. Its just when I measured the CDN for jQuery I compared the microsoft and the Google the google seemed more responsive. Googles seemed better then local storage.
    http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js
    versus
    http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js
    >One of the key things about the CDN is that it allows sharing of the same file across sites.
    Yes I read this article about CDN and why it is better. That is what got me into using it.
    http://encosia.com/3-reasons-why-you-should-let-google-host-jquery-for-you/
This discussion has been closed.