Wasting bandwidth on <img>

Posted on 2009-02-20
Last Modified: 2012-05-06

Just double-checking - when we have an html page like this, hosted at

    <img src = "" />

then the site is the one actually expending bandwidth on serving the image up to the browser, right? Even though the user is viewing the page hosted at, the other guy is basically paying for the bandwidth?

Is there some way to stop people from doing that, as I might be hosting a lot of images and would not like people leeching off my site, wasting my bandwidth.

Question by:DJ_AM_Juicebox
    LVL 9

    Expert Comment

    Host the images on a free image hosting site and point to them with the img src tag.


    Author Comment

    If I hosted them on a free image hosting site, wouldn't that be wildy innapropriate? I mean I'd be blatently wasting their bandwidth with possibly hundreds of thousands of images - are there any services that don't mind doing this?

    LVL 9

    Expert Comment

    Heres the thing answer your original question, yes is the site that get hit with the bandwidth for serving images.  

    I guess Im not fully understanding your question then.  What is it you trying to stop people from doing?  hosting images on your site (they're taking your bandwidth)?  I ask because from how you worded it, it sounds like your have a website (, but your hosting images on another domain ( will get all the bandwidth traffic.  
    LVL 9

    Expert Comment

    Sorry, hit submit on accedent....

    As for services that dont mind doing this...thats why theyre free :).  They host images for people (with certain limits) in hopes that it will draw them to theire membership services.  Anyway, if you dont want to pay for the bandwidth, then put the images on and host them there.  Whoever hosts the images, will get the bandwidth.  
    LVL 42

    Accepted Solution

    LVL 5

    Expert Comment

    If your server has cPanel, there should be an icon with options to prevent image hotlinking & leeching.

    Author Comment

    Yeah sorry if I was not clear.

    I wrote some client software which lets people make pictures. They can then upload these images to my website, and then others can check them out and download them again to the client software for re-editing.

    So I have a choice here as I see it:

    1) I can host the images myself on my own webserver. I can pay ~$12 a month for a godaddy account which gives me unlimited bandwidth and disk storage. Even with the minimum plan, I can still store about 300,000 images before space becomes a problem. My concern here though is that if people start linking a lot to these user-generated images, I'm gonna be hit with a lot of bandwidth usage without getting any benefit for it (i dont mind if people link and come to the actual site and look at ads, but I don't want people to just see the raw images without getting credit for them!)

    2) I can try hosting the images at one of these free image hosting sites,  people come to my pages which I'm still serving but just point the <img src=""> to that free site. My concern with this is that the free host would get absolutely no credit, since my users would never visit their site, they'd just see the images served up by them in the context of my own pages. That's one concern, the other is if the free host sees I'm hosting like a million images they may decide to pull the plug on my operations and that just breaks my whole site and all my images be be lost!

    So, trying to balance which route to take here,

    LVL 5

    Expert Comment

    I believe I would personallyopt for the first option, basically because of several things, but some I can think of:

    1) Possible issues with rights of images when hosted by a third-party (read carefully their policies...)
    2) What you said: if they pull the plug, your website is broken. If that website goes down for maintenance, so does yours. And you do not choose when this happens.
    3) Not every third-party image hosting provider allows the images being deleted from their servers, whereas if you host them in your server, you have the control.

    If you fear other sites leeching your images for bandwidth grounds, enable an anti-hotlinking system. If the concerns are because of no credit being given to the author, consider watermarking the images or displaying them in low resolution (but downloadable in normal quality).

    LVL 2

    Expert Comment

    it's simple.

    rather then serving out the actual image, have all of your links point to a image serving script. in that script, you look at the referrer and if it's not your site (or from a list of allowed hotlinkers - for instance google images, etc) then show them a no hyjack image instead of the one they want to see.

    if you don't want the image URL to look like this though:

    <img src="image.asp?id=kfadkljfadkljfadsljkadljk" />

    you can use pretty links with creative 404 page...

    <img src="myimage.jpg" /> the file doesn't really exist at that location, but the 404 error knows what you really mean and sends it to the image script which then serves out the actual image.

    clear as mud?

    Author Comment

    Ok yeah I agree it's best if I host them, but I don't understand the "image serving script". How would that work, can you give a small example or link?

    LVL 2

    Expert Comment

    sure - (example in asp classic - but can be translated to any other language easily enough)

    [I personally like using the 404 approch myself]

    if images are shown as being hosted here: /images/user/file.jpg
    you actually put them here: /actual/images/user/file.jpg

    now, all of your image links should point to the wrong place forcing a 404 error
    in your custom 404 page you make it look at the url and if it's "/images/user" you redirect to:


    now comes the fun part - /includes/image.asp looks like the following:
    '// note, no error correction has been added.
    function showImg(byVal Src)
    	dim ref: ref = request.serverVariables("http_referer")
    	dim yourdomain : yourdomain = ""
    	'/* check that the request for the image is coming from within your server
    	' of coarse, i would suggest a more comprehensive method of validation
    	' for instance. on my anti-hyjack script, i have a DB list of allowed referrers
    	' if the referer is illegal, change the URL
    	if(instr(ref, [yourip])=0 and instr(ref,[yourdomain])=0) then	
    		Src = "/actual/youAreAnIdiot.jpg"
    		Src = "/actual" & Src
    	end if
    	'/* now serve the image */
    	'/* create an output stream object */
    	Dim objStream : Set objStream = server.createObject("ADODB.Stream")
    	'/* telling the stream to be binary */
    	objStream.Type = 1 
    	Call objStream.LoadFromFile(Src)
    	Response.ContentType = "image/jpeg"
    	Call Response.BinaryWrite(objStream.Read)
    	'/* Clean up.... */
    	Set objStream = Nothing	
    end function

    Open in new window


    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
    The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now