addSizes.js
Snazzy automatic link file-size generation
http://natbat.net/2008/Aug/27/addSizes/
Often in the development of a site I come across the need to display the size of a document next to the link targeting it. I also like to display the type of file the link targets, for example, when linking to pdfs, mp3s or Word documents.
These indications distinguish the ‘attachment’ link from a normal web link, whilst also giving the user some inkling of the time they will need to wait to view the resulting content.
very file on the web, be it a web page, a text file or whatever has HTTP headers associated with it. This is meta information about the file that is sent before the actual contents of the file itself. Included in this meta information is the size of the document.
You can call json-head with JavaScript (JSONP). It takes the URL of a file on the web and performs a HEAD request against it to return the headers and not the actual content itself. The application then returns this information in JavaScript object notation (JSON) to a callback function you have written.
script · · 329 similars
Rank: unranked · Posted on Sep 04, 2008
