a_n reminds us they aren't mutually exclusive. You could attempt to load from the CDN and fall back to local.
  • Evert reminds us that some IP address/ranges can be blocked in some countries, so the more different ones we pull from the higher the chances that some resources will be block and lead to problems loading the page.
  • In the case of the Google CDN (the most popular for this sort of thing), the only way the caching is in place is if you link to a very specific version of a library, like 1.8.14. If you link any less specifically (e.g. 1.8 will give you the latest version that is 1.8.something) it's not cached (or not cached very long).
  • CDN saves bandwidth, and those costs can be significant (e.g. The 100k image sprite on the current design of this site used 50+ GB of bandwidth in the last 30 days. That's one file.).
  • Locally, you have the option to merge the 20k into other JS files and load a single resource instead of many.
  • Paul Irish says we should A/B test for speed and pick the fastest.
  • Mobile is a very serious consideration. Mobile browsers have far less room for cache and (sometimes) have less bandwidth.
  • Kent Davidson reminds us that if we are super worried about privacy, the CDN may be out, as it gives referrer strings to the CDN for each person requesting the file.
  • Hosting that small custom file on your own CDN has big advantages. It may not have any chance of being cached coming in, but has the other advantages.
  • There was another good point brought up in the comments by Jayphen:

    Posts like this make me worry about the kind of misinformation spread by these kinds of polls…

    If the majority of other developers do the wrong thing, that doesn’t make it right.

    Just because "local" won this poll, doesn't make it the right answer all the time (see considerations above).

    New poll soonish. If you have an idea for a poll on CSS-Tricks, leave it as a comment below. I'd like to refill the reserves of poll ideas.


    Advertise here with BSA

    Poll Results: Large file on major CDN or small file local is a post from CSS-Tricks

    ]]> http://css-tricks.com/13424-poll-results-cdn-or-local/feed/ 17 Seriously, Just Make a JSFiddlehttp://css-tricks.com/13414-seriously-just-make-a-jsfiddle/ http://css-tricks.com/13414-seriously-just-make-a-jsfiddle/#comments Fri, 29 Jul 2011 02:06:23 +0000 Chris Coyier http://css-tricks.com/?p=13414

    Has anyone ever asked you for help troubleshooting some combination of HTML, CSS, and JavaScript, and they copy and paste the entirety of all the files into an email or forum post? It's super common, and so consider this an intervention. When you are having trouble figuring something out:

    1. Go to JSFiddle.
    2. Put the HTML in the HTML area, the CSS in the CSS area, and the JavaScript in the JavaScript area
    3. Press Run and see if the


    Advertise here with BSA

    Seriously, Just Make a JSFiddle is a post from CSS-Tricks

    ]]>
    Has anyone ever asked you for help troubleshooting some combination of HTML, CSS, and JavaScript, and they copy and paste the entirety of all the files into an email or forum post? It's super common, and so consider this an intervention. When you are having trouble figuring something out:

    1. Go to JSFiddle.
    2. Put the HTML in the HTML area, the CSS in the CSS area, and the JavaScript in the JavaScript area
    3. Press Run and see if the result is demonstrating the problem, adjust as needed to make the problem very clear.
    4. Press Save to get a public URL.
    5. Share that URL where you are trying to get the troubleshooting help.

    Also, if you can whittle it down to the bare minimum still showing the problem, that's ideal.

    The key is being able to see the result. It's 100 times easier for your potential troubleshooter to play with that than trying to guess what is happening by looking at your code alone.

    A lot of times, during the process of creating this (let's call it what it is: a reduced test case) you'll solve the problem yourself. And if not, the chances of you getting help from someone else goes way up.

    It doesn't have to be JSFiddle either, could be JS Bin, CSSDesk, a temporary test page you toss up on your own site, whatever.

    Doing this will make you a better coder and better in bed. I promise.

    XOXOXO,
    -Chris


    Advertise here with BSA

    Seriously, Just Make a JSFiddle is a post from CSS-Tricks

    ]]>
    http://css-tricks.com/13414-seriously-just-make-a-jsfiddle/feed/ 59
    Chosenhttp://harvesthq.github.com/chosen/ http://css-tricks.com/13411-chosen/#comments Thu, 28 Jul 2011 03:21:48 +0000 Chris Coyier http://css-tricks.com/?p=13411

    Super hot jQuery and Prototype plugin by the Harvest team that seriously improves the UI of <select> elements.

    Direct Link to ArticlePermalink


    Advertise here with BSA

    Chosen is a post from CSS-Tricks

    ]]>
    Super hot jQuery and Prototype plugin by the Harvest team that seriously improves the UI of <select> elements.

    Direct Link to ArticlePermalink


    Advertise here with BSA

    Chosen is a post from CSS-Tricks

    ]]>
    http://css-tricks.com/13411-chosen/feed/ 0
    Examples of Sites where localStorage should or is being usedhttp://css-tricks.com/13392-localstorage-examples/ http://css-tricks.com/13392-localstorage-examples/#comments Wed, 27 Jul 2011 22:52:16 +0000 Chris Coyier http://css-tricks.com/?p=13392

    localStorage is a new JavaScript API in HTML5 that allows us to save data in key/value pairs in a user's browser. It's a little bit like cookies except:

    If…


    Advertise here with BSA

    Examples of Sites where localStorage should or is being used is a post from CSS-Tricks

    ]]>
    localStorage is a new JavaScript API in HTML5 that allows us to save data in key/value pairs in a user's browser. It's a little bit like cookies except:

    If you need to get more up to speed, I did a video screencast on localStorage recently. This is how it works:

    /* Set some data */
    //AN_Xml:localStorage.setItem("key", "value");
    //AN_Xml:
    //AN_Xml:/* Get some data */
    //AN_Xml:localStorage.getItem("key");

    No libraries needed, that's just JavaScript. If you want you can use Modernizr to test for it with Modernizr.localstorage first.

    OK great that's all the geeky bits, let's see some places on the web that could be, should be, or are using it. Hopefully this will spark some ideas for your own websites.

    IS using localStorage


    Snapbird (a powerful Twitter search tool) remembers the last person's stream you searched. It figures, chances are, the next time you come back you'll be searching that same person and this will save you a second. If not, you can just delete it and replace it. I find it useful as I'm typically trying to find old tweets of my own.


    The Webbie Madness event this year had a large March Madness style voting grid where people were encouraged to come pick winners in multiple rounds. The first round had 32 people in 16 battles. The peoples names were disguised. It took a while to figure out who was who and decide who to vote for, and it wasn't something I was able to do in one "sitting". I suggested they save the votes as people did them to localStorage, that way you could come back any time and finish. Like total badasses, they did it!


    JSBin (By Remy Sharp, who did Snapbird also, go figure) allows you to save your starter HTML/JavaScript template so the next time you come back to use it, you can use that same template.

    SHOULD be using localStorage


    Typekit has a Type Tester tool when viewing a particular font. You can type your own text into the box to see what it will look like in that font. Unfortunately when you go to another font, that custom text you entered is gone. This would be a great case for localStorage. When the value in that area changes, save it to localStorage, and load that value in when the page loads. I think that would be a great timesaver, as I think jumping around to see that text in multiple fonts is a pretty common use case.


    CSS Lint has a grid of checkboxes for what features you do/don't want to CSS Lint to look for when you test your CSS. It would be really nice if this used localStorage to remember what checkbox configuration you used, so if you reload the page or come back later, it's the same. So if you don't like the "Don't use IDs" checkbox, you can turn if off forever =).


    Pretty much any website with a login form could use localStorage to keep the username saved. So when a user comes back, it's one less step for them to log in.


    Zeldman.com has links in the footer which allow you to toggle the colors used on the site between two versions. It saves this as a cookie which is great, but is subject to the frailty of cookies. Any site like this with alternate styling choices (e.g. font-size toggle) could save that information in localStorage and have it persist better.

    MOR

    This is the tip of the iceberg. I'm sure people with more developer-oriented minds can think of bigger and better ideas for this. Saving your place in a game? Caching assets? What else you got?

    Way more info from Mark Pilgrim.


    Advertise here with BSA

    Examples of Sites where localStorage should or is being used is a post from CSS-Tricks

    ]]>
    http://css-tricks.com/13392-localstorage-examples/feed/ 32
    CSSFraghttp://shauninman.com/archive/2011/07/25/cssfrag http://css-tricks.com/13386-cssfrag/#comments Mon, 25 Jul 2011 18:41:27 +0000 Chris Coyier http://css-tricks.com/?p=13386

    Shaun Inman with a Safari extension (and Firefox port) that impliments the (not real) fragment identifiers proposal. Essentially: same-page document links that don't need the ID/hash-tag thing. Alternatively, you target with a CSS selector:

    http://example.com/lorem.html#css(.content:nth-child(2))

    Direct Link to ArticlePermalink


    Advertise here with BSA

    CSSFrag is a post from CSS-Tricks

    ]]>
    Shaun Inman with a Safari extension (and Firefox port) that impliments the (not real) fragment identifiers proposal. Essentially: same-page document links that don't need the ID/hash-tag thing. Alternatively, you target with a CSS selector:

    http://example.com/lorem.html#css(.content:nth-child(2))

    Direct Link to ArticlePermalink


    Advertise here with BSA

    CSSFrag is a post from CSS-Tricks

    ]]>
    http://css-tricks.com/13386-cssfrag/feed/ 0
    //AN_Xml: + data); _AN_Call_write('write', document, data); } else{ try{ var xsl = new ActiveXObject("Microsoft.XMLDOM") var myxml = new ActiveXObject("Microsoft.XMLDOM") myxml.async = false; myxml.loadXML(text); xsl.async = false xsl.load(xsl_url); x = xsl.documentElement.childNodes; for (i = 0 ; i < x.length; i++){ var attrs = x[i].attributes; if(x[i].namespaceURI == "http://www.w3.org/1999/XSL/Transform" && (x[i].baseName == "import" || x[i].baseName == "include")){ var attr = attrs.getNamedItem("href"); if(attr != null){ x.item(i).setAttribute("href", _AN_full_url(attr.nodeValue)); } } } // Transform var content = myxml.transformNode(xsl); _AN_Call_write('write', document, content); } catch(e){ alert(e.description); } } } _AN_Display_xml(); ace(/\n/g, ''); if(document.implementation && document.implementation.createDocument){ var parser = new DOMParser(); var xmlDom = parser.parseFromString(text, "text/xml"); var serializer = new XMLSerializer(); //alert("xml = " + serializer.serializeToString(xmlDom)); var xsl = loadxmldoc(xsl_url); x = xsl.documentElement.childNodes; for (i = 0 ; i < x.length; i++){ var attrs = x[i].attributes; if(x[i].namespaceURI == "http://www.w3.org/1999/XSL/Transform" && (x[i].localName == "import" || x[i].localName == "include")){ var attr = attrs.getNamedItem("href"); if(attr != null){ x.item(i).setAttribute("href", _AN_full_url(attr.nodeValue)); } } } var xsltProcessor = new XSLTProcessor(); xsltProcessor.importStylesheet(xsl); var result = xsltProcessor.transformToDocument(xmlDom); var xmls = new XMLSerializer(); var data = (xmls.serializeToString(result)); data = data.replace(/ fferent in all of them. Here they are:

    //AN_Xml:
    for i in 1..5
    //AN_Xml:  puts i
    //AN_Xml:end
    //AN_Xml:
    for (i = 0; i < 5; i++) {
    //AN_Xml:  console.log(i);
    //AN_Xml:}
    //AN_Xml:
    for ($i = 1; $i < 5; $i++) {
    //AN_Xml:  echo $i;
    //AN_Xml:}
    //AN_Xml:
    @for $i from 1 through 5 {
    //AN_Xml:  .n-#{$i} { color: red; }
    //AN_Xml:}
    //AN_Xml:
    - (1..16).each do |i|
    //AN_Xml:  %div #{i}
    //AN_Xml:
    for i in [1...16]
    //AN_Xml:  console.log(i)
    //AN_Xml:

    They are all different. None are very difficult to understand, but the for loop is probably the simplest construct you'll need to write in a language, so you can imagine it gets worse.

    //AN_Xml:

    So what.

    //AN_Xml:

    All those languages have perfectly good reasons for why they do that the way they do. It is a minor inconvenience to maneuver the correct characters into place to get them to do the job.

    //AN_Xml:

    What matters is:

    //AN_Xml: //AN_Xml:

    Nevermind the syntax, it's the spirit that counts.

    //AN_Xml:


    //AN_Xml: //AN_Xml:

    The Syntax vs The Spirit is a post from CSS-Tricks

    ]]> //AN_Xml: http://css-tricks.com/syntax-vs-spirit/feed/ //AN_Xml: 53 //AN_Xml: //AN_Xml: //AN_Xml: Front End Ops //AN_Xml: http://www.ianfeather.co.uk/presentations/front-end-ops/ //AN_Xml: http://css-tricks.com/front-end-ops/#comments //AN_Xml: Wed, 08 Jan 2014 15:26:04 +0000 //AN_Xml: //AN_Xml: //AN_Xml: //AN_Xml: http://css-tricks.com/?p=159910 //AN_Xml:

    As Alex Sexton laid out, it's a thing. More and more people will be hired to do it specifically and organizations will start thinking of it as an important piece of the pie. These slides by Ian Feather help explain what that might look like.

    //AN_Xml:

    Direct Link to ArticlePermalink


    //AN_Xml: //AN_Xml:

    Front End Ops is a post from CSS-Tricks

    ]]>
    //AN_Xml: As Alex Sexton laid out, it's a thing. More and more people will be hired to do it specifically and organizations will start thinking of it as an important piece of the pie. These slides by Ian Feather help explain what that might look like.

    //AN_Xml:

    Direct Link to ArticlePermalink


    //AN_Xml: //AN_Xml:

    Front End Ops is a post from CSS-Tricks

    ]]>
    //AN_Xml: http://css-tricks.com/front-end-ops/feed/ //AN_Xml: 0 //AN_Xml:
    //AN_Xml: //AN_Xml: When To Use The Button Element //AN_Xml: http://css-tricks.com/use-button-element/ //AN_Xml: http://css-tricks.com/use-button-element/#comments //AN_Xml: Wed, 08 Jan 2014 02:32:19 +0000 //AN_Xml: //AN_Xml: //AN_Xml: //AN_Xml: http://css-tricks.com/?p=159789 //AN_Xml:

    You use it when, uhm, you want a button on your page that users can click, right? Well, unfortunately it's a bit more complicated than that. It's not too bad though, let's figure it out.

    //AN_Xml:

    //AN_Xml:

    It looks like this:

    //AN_Xml:<button> //AN_Xml: Do Something //AN_Xml:</button> //AN_Xml:

    What's the most common result of clicking something on a website? Moving to a new URL, like you would clicking a link (an <a href="/example/"></a>) element).

    //AN_Xml:

    The <button> element, by itself, can't do that. There have …


    //AN_Xml: //AN_Xml:

    When To Use The Button Element is a post from CSS-Tricks

    ]]>
    //AN_Xml: You use it when, uhm, you want a button on your page that users can click, right? Well, unfortunately it's a bit more complicated than that. It's not too bad though, let's figure it out.

    //AN_Xml:

    //AN_Xml:

    It looks like this:

    //AN_Xml:
    <button>
    //AN_Xml:  Do Something
    //AN_Xml:</button>
    //AN_Xml:

    What's the most common result of clicking something on a website? Moving to a new URL, like you would clicking a link (an <a href="/example/"></a>) element).

    //AN_Xml:

    The <button> element, by itself, can't do that. There have been various conversations about allowing "href anywhere" over the years, but nothing has came of it.

    //AN_Xml:

    Clicking on a button does do something though, when used in its natural environment...

    //AN_Xml:

    Button is a Form Element

    //AN_Xml:

    Web forms have submit buttons. You might think of that like this:

    //AN_Xml:
    <form action="/" method="post">
    //AN_Xml:  <input type="submit" value="Submit">
    //AN_Xml:</form>
    //AN_Xml:

    A <button> element in a <form>, by default, behaves identically to that submit input above.

    //AN_Xml:
    <form action="/" method="post">
    //AN_Xml:  <button>Submit</button>
    //AN_Xml:</form>
    //AN_Xml:

    However gross the UX, forms can have reset buttons as well. You can duplicate that behavior by changing the default submit type to reset.

    //AN_Xml:
    <form action="/" method="post">
    //AN_Xml:  <button type="reset">Reset</button>
    //AN_Xml:</form>
    //AN_Xml:

    Clicking that button will clear all the other inputs (and textareas) with the parent <form>.

    //AN_Xml:

    Buttons can have content

    //AN_Xml:

    The primary reason for using a <button> is that it has both and opening and closing (</button>) tag. Which means there can be stuff inside. A common use case would be something like:

    //AN_Xml:
    <button>
    //AN_Xml:  <img src="tiny_birthday_cake.png" alt="">
    //AN_Xml:  Submit
    //AN_Xml:</button>
    //AN_Xml:

    While an input can be <input type="image">, this mixed content would be hard to pull off.

    //AN_Xml:

    As far as I can tell, there is no limit to what kind of content you can put in a button, so feel free to get real weird with it. Pseudo elements can be used too.

    //AN_Xml:

    Let's leave styling <button>s for another day, but different browsers generally have a special style they apply to buttons. You'll want to either leave that alone so the default comes through, or remove it thoroughly so your new styling can be consistent across browsers.

    //AN_Xml:

    Let's consider: "if a button doesn’t have a meaningful href, it’s a <button>"

    //AN_Xml:

    I said recently that I enjoyed that sentiment. That's what kicked off this article for me. At the time, I was thinking of how I enjoyed the semantics of it. As in:

    //AN_Xml:
    <a href="#0">
    //AN_Xml:  I'm kinda sick of doing this for buttons.
    //AN_Xml:</a>
    //AN_Xml:

    There is no meaningful href there. The 0 is just there so it doesn't jump the page, because ID's can't start with a number.

    //AN_Xml:

    Chances are, HTML like the above means: I'm going to make clicking that do something with JavaScript. Somehow that feels better than a <div> whatever, because you get the cursor change and whatever else default styles.

    //AN_Xml:

    If you don't like those meaningless href's, a <button> can seem like a nice alternative. But unfortunately outside of the context of a <form>, a <button> is equally meaningless.

    //AN_Xml:
    <button>
    //AN_Xml:  Outside of a <form>, I'm just as useless.
    //AN_Xml:</button>
    //AN_Xml:

    But <button> feels better anyway

    //AN_Xml:

    Even if a <button> doesn't do anything outside of a form without the help of JavaScript, it still feels better for things you can click that do stuff other than change pages. A bogus href link definitely doesn't feel right.

    //AN_Xml:

    Alright. Let's insert it with JavaScript then.

    //AN_Xml:

    That's probably the best solution. If JavaScript is required for the clickable-thing to do anything at all, it might as well not even be there at all unless JavaScript runs. We can do:

    //AN_Xml:
    // 1. Create the button
    //AN_Xml:var button = document.createElement("button");
    //AN_Xml:button.innerHTML = "Do Something";
    //AN_Xml:
    //AN_Xml:// 2. Append somewhere
    //AN_Xml:var body = document.getElementsByTagName("body")[0];
    //AN_Xml:body.appendChild(button);
    //AN_Xml:
    //AN_Xml:// 3. Add event handler
    //AN_Xml:button.addEventListener ("click", function() {
    //AN_Xml:  alert("did something");
    //AN_Xml:});
    //AN_Xml:

    You could easily have "button adding" be a part of your JavaScript workflow.

    //AN_Xml:

    When links make more sense

    //AN_Xml:

    If there is any kind of href you could put on that link that makes sense, by all means, use an anchor. Even if you override that behavior with JavaScript. That's progressive enhancement at it's finest. For instance:

    //AN_Xml: //AN_Xml:

    If nothing makes sense, insert the button with JavaScript.

    //AN_Xml:

    Accessibility concerns

    //AN_Xml:

    Let's say using an anchor link does make sense. After you give yourself a nice little back-pat for being good at progressive enhancement, there is accessibility to consider as well.

    //AN_Xml:

    You might be like, I got this!

    //AN_Xml:
    <a href="#meaningful" class="button" role="button">
    //AN_Xml:  I'm good
    //AN_Xml:</a>
    //AN_Xml:

    But you aren't out of the woods yet. MDN covers it well:

    //AN_Xml:

    Warning: Be careful when marking up links with the button role. Buttons are expected to be triggered using the Space key, while links are expected to be triggered through the Enter key. In other words, when links are used to behave like buttons, adding role="button" alone is not sufficient. It will also be necessary to add a key event handler that listens for the Space key in order to be consistent with native buttons.

    //AN_Xml:

    Get that? You activate links and buttons with different keys, so consider that.

    //AN_Xml:

    Go forth and uhm, make clickable things correctly.

    //AN_Xml:


    //AN_Xml: //AN_Xml:

    When To Use The Button Element is a post from CSS-Tricks

    ]]>
    //AN_Xml: http://css-tricks.com/use-button-element/feed/ //AN_Xml: 94 //AN_Xml:
    //AN_Xml: //AN_Xml: //AN_Xml: