Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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:

  1. 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.

  2. 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?

  3. 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?

  4. 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.

share|improve this question

1 Answer 1

Is there any good reason why you can't use amazon S3? The costs on a file of that size would be tiny and they take care of all the load issues. Bundle it with Cloudfront so you get the full benefits of a CDN. I would be amazed if you couldn't afford this.

For example I punched your 50k file into the Amazon S3 calculator http://calculator.s3.amazonaws.com/calc5.html at a million hits a month and it will cost you ~$6 a month (taking into account the free tier).

If you go an order of magnitude higher at 10 million hits a month you are looking at about $80 a month, which is significantly cheaper than dealing with that kind of load yourself. S3 will keep scaling with your load, unlike your dedicated server.

Cloudfront is an extra cost that you might not need initially, but may become worthwhile once you get established.

share|improve this answer
Yes, agree. I might not need a cdn even until it's a very very high traffic. I agree, that in the 'near' future, I could switch to amazon S3. And have the same domain I'm using point to it. My real worry is not geolocation. It's scaling the file actually. Any other advice? –  Dayson Dec 13 '10 at 7:48
If geolocation is not an issue and scale is your main concern, S3 is definitely where I would host the file, from the start. I don't see a lot of advantage to hosting the file on your own servers, then having to migrate your domain etc to point to S3 later. Save yourself the hassle and do it right from the start, S3 is only pay for what you use, so if its not popular at the start it will cost you just cents per month. –  micmcg Dec 14 '10 at 6:09
I'm a little confused. How does S3 calculate the bill? Is it on the number of get requests or on the 'bandwidth' used? The calculator I see only talks about get requests a month. –  Dayson Dec 14 '10 at 9:00
There's several factors. 1. Space used to store the file. 2. Bandwidth used to serve the file. 3. Number of requests for the file. The calculator I linked to should let you adjust all these factors. Also consider upvoting or accepting this answer if it helps you. –  micmcg Dec 14 '10 at 23:28
I see. I couldn't find the calculator option in the amazon s3, but I guess it is accounted for the entire amazon web service itself. I don't think with bandwidth costs + requests cost, the cost per month would be as low as $6. Could you PLEASE give me the values you used for the calculation? p.s: i would upvote.. but i dont have the credits for it yet, should get it soon and do the do for you :-) –  Dayson Dec 16 '10 at 20:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.