Why is it so difficult to view *just* the image?

281 views

Many websites, reddit included, make it difficult or possibly impossible to simply view an image, by itself, without the accompanying website around it, even when you click “open image in new tab”. How does this work, and is it possible to force the browser to just show the image?

edit: yes I know *why* websites do it, it’s because they’re jerks and don’t want it embedded. the question is more about why web browsers just go along with it. if I tell my web browser to display an image, I obviously don’t want it to display an entire website, and that shouldn’t be something the website can control.

In: 9

4 Answers

Anonymous 0 Comments

The other comments covered the why, so I’ll take a crack at covering **how**.

When your browser tries to open a URL, it really just connects to the server at the IP address that the domain (for example www.reddit.com) points at, and then passes the rest of the URL, along with some other information, to the server and waits for a response.

What response the server gives is entirely up to how it is configured. You can make a server that is configured to respond with an image file in response to you asking for theimage.jpg on yourdomain DOT com on weekdays, but a text file containing ‘Gone for the Weekend’ during the weekend instead.

This configuration could also take into account some of the information that your browser sends besides the URL itself. One of these pieces of information is what is called the ‘Referer’ ([Yes, the mispelling of Referrer is intentional](https://en.wikipedia.org/wiki/HTTP_referer)). When your browser renders a webpage, it usually needs to download all sorts of additional images and other files to be shown on it. The webpage itself specifies the URLs to all of these pages, and your browser then automatically makes additional requests to the server to get these files. Each of these additional requests will have the URL of the webpage itself set as their ‘Referer’, and the server can then see this to determine if you’re trying get an image because you’re viewing the webpage it is shown on, or you’re trying to open the image file directly (in which case no ‘Referrer’ data would be sent).

So what is sorta happening with Reddit images is that when you try and open it in a new tab, the Reddit server sees that you’re trying to access the URL directly, and just serves you the webpage it is shown on as the response. But when your browser then requests the same URL as part of rendering the webpage, the server responds with the actual file because it it can see that you’re already on the webpage showing it.

Your browser has no control over what response the server decides to respond with. The way the browser behaves with the ‘Referer’ data has been part of HTTP browser standards for ages and was included in the standard to begin with precisely to give servers the ability to vary how they respond based on it. This is unlikely to change just because some sites decide to use it in a user-unfriendly way.

If this practice becomes prevalent enough among larger websites, I’d expect browser plugins to start popping up that allows you to fake the type of requests that show the actual image when you open them in a new tab.

You are viewing 1 out of 4 answers, click here to view all answers.