ShareThis Forums » ShareThis Wish List

ShareThis optimization, specifically via caching

(6 posts)

  1. peterj
    Member

    Adding the ShareThis widget to my highly-cachable website has decreased the perceived load time of pages substantially. The CSS, JavaScript and icon are all retrieved on every page load, since they don't include HTTP headers (like Expires and Cache-Control) to suggest that they be cached, and even in the last few weeks as ShareThis has become more popular I've noticed the retrieval of resources on r.sharethis.com and w.sharethis.com taking longer.

    I know you want to keep track of every single view, but I think there's a tradeoff to be made with providing a good end-user experience. I'd rather have a fast site without ShareThis than a slow one with the button.

    Mark Nottingham's "Cacheability Engine" is a handy tool to investigate/evaluate behaviour, as is Yahoo!'s YSlow extension for Firebug.

    Posted 7 months ago #
  2. nettrotter
    Member

    decreased the perceived load time of pages substantially.

    This sounds very exciting.

    Posted 7 months ago #
  3. tdevries
    Member

    Are you talking about the load of the button itself? If so, does it make any difference if you create a custom button? I am testing the following solution:

    1. Put the script in the HTML header.
    2. Where I want the link -- without image, and using my own CSS -- put something like this: <a id="pageShare" href="javascript:void(0);">Share This Page</a>
    3. In an onLoad JavaScript function, attach the ShareThis to that link: var shareObject = SHARETHIS.addEntry({title:shareTitle},{button:false}); var shareElement = document.getElementById("pageShare"); shareObject.attachButton(shareElement);

    Works in Firefox and Safari. Still testing in IE. I wonder if this would cause less delay on load because it's just pulling in the JavaScript file, not the icon at all.

    I've also noticed that the initial JS is about 20kb, and seems to be based on MooTools. My site already uses the jQuery framework. It would be cool if there was a jQuery version of ShareThis that could be a little smaller. And it would be nice if the JS could be optimized to save data space. Simply replacing all the indent spaces with indent tabs shaves roughly 3kb off of the file size, bringing it to around 17kb (I just ran some tests in BBEdit). Running JSMin on it shrinks it to under 14kb (though I don't know if the code works as well).

    Posted 7 months ago #
  4. peterj
    Member

    Using local resources for the image and CSS makes sense---I think I'll try your idea. Downloading that 20k script for every page is still a big hit though; for example, depending on the page on my blog-like site it's anywhere from 1/2 the size of the unique and/or non-cacheable components to five times their size. 14k is a nice size reduction, and if you gzip the jsmin version you're down to 5k. Still, no re-download at all would be best.

    Posted 7 months ago #
  5. tdevries
    Member

    This works in IE. Note that it is basically a customized version of the code that ShareThis provides here.

    Seems like we could create our own rotating graphic icon of the social networking sites. It would be cool if ShareThis provided this as a downloadable GIF, but short of that, I don't see why we couldn't assemble our own and use it as a local, cachable image. There's nothing in the Terms of Use against this, though I think it may have to start with the ShareThis icon itself. I may try it out.

    Note that the 20k file may still be cachable, even if it is loaded from ShareThis.com; there is nothing to say it isn't.

    Also, I've done some testing with the initial JS file. Copy the URL from the JS link into your web browser bar, and you'll pull up the JS text itself. This is customized based on the ShareThis parameters passed in the URL. You can save this text as a JS file to your web server, then refer to that file instead of the remote file. This makes it local and perhaps more cachable, and it still works nicely. However, there is a major caveat: should ShareThis ever change their code (perhaps to reflect changes in URLs, servers, etc.), your ShareThis code will almost certainly break, and you will have to update it with a fresh copy. And it might be against their TOU...?

    (Also, I inadvertently included some custom JS in the sample code above. The section {title:shareTitle} should be {title:document.title}.)

    Posted 7 months ago #
  6. tdevries
    Member

    Two clarifications:

    1. If you save the JS to your local server, it's more cacheable because you won't need to include the query string in your script tag reference. You'll only need the "sharethis.js" reference (or whatever you call the file). If you were really fastidious, you could write a server-side script (Perl, PHP, etc.) to routinely ping your ShareThis JavaScript URL and save the text to a local file. Then you would have the benefits of local hosting, cacheability, and the [almost] latest version of the ShareThis code.

    2. I should clarify what I meant by "the 20k file may still be cachable, even if it is loaded from ShareThis.com; there is nothing to say it isn't." Browsers may still cache this, but it's not predictable, and the query string in the URL makes it less likely. But it is still possible (just unlikely).

    Posted 7 months ago #

RSS feed for this topic

Reply

You must log in to post.