Hosting a javascript api file for third party sites the way sharethis, uservoice, analytics do it.
Posted
by
Dayson
on Server Fault
See other posts from Server Fault
or by Dayson
Published on 2010-12-12T23:35:16Z
Indexed on
2011/02/03
7:27 UTC
Read the original article
Hit count: 565
I'm preparing to launch a service soon which will provide third party websites a widget. The widget requires my javascript file in the website's code. Exactly the same way services like analytics, uservoice, sharethis, getclicky, etc provide you with a javascript snippet to add to your page.
Therefore, my javascript file is going to be hotlinked by tons of websites which possibly receive a lot of requests too.
I need advice/opinions on the following aspects:
What's the right location for hosting this file? Should I use a sub-domain for it? I was thinking of something like http://api.myservice.com/js/foo.js . Remember, once websites start embedding this file, its location CANNOT change under any circumstances.
Right now we can afford just one dedicated server. So I have minified my file, enabled gzip and plan to use some good cache control headers through apache. Also, in the near future when the requests pickup, I will use a http proxy like Varnish. Is this a good plan for the near future?
Should I be considering a CDN in the future (since we can't afford it now)? If so how do I make sure we're prepared to migrate to it without breaking services. Pros/Cons of moving just this file to a CDN? Also, since its just one javascript file(50kb), any affordable CDN so we could consider it in the beginning itself?
Any other word of advice I could use? Anything I shouldn't overlook at this stage which I would regret later? (both in terms of server + javascript ajax limitations)
Thanks in advance.
© Server Fault or respective owner