0

Just wondering if it makes any difference to Google whether or not I URL encode the image names when linking to them.

For example if I have an image named "test-1234-!.jpg", does it make a difference if I name it refer to it as "test-1234-%21.jpg"?

The reason I am asking is because I am doing a major shift in the way my website works and while all new image names will not be URL encoded, all of the past ones are. I want to see if it is worth it renaming all of them or if I should just leave it like that.

2
  • 1
    This is "URL encoding", rather than "HTML encoding". Presumably when you say "renaming all of them", you don't literally mean "renaming the file", but the "URL in the HTML document"?
    – MrWhite
    Commented Oct 17, 2012 at 16:38
  • Yes sorry, I meant URL encoding. And yes I mean the URL pointing to the image itself. Commented Oct 17, 2012 at 16:41

1 Answer 1

2

See RFC 3986 - Uniform Resource Identifier (URI): Generic Syntax about the gory details of Url encoding. You should always urlencode your references, keep things standard conform and this way don't break your clients requests.

Google Bot will be happy if it can fetch all your linked assets and this is what you want. Of course the bot is able to url-decode your references/links.

Don't be tricked that it looks some sites do not urlencode: Almost everytime the browser already decoded a urlencoded link just for user readability (e.g. in the address bar). If you look at the source you'll notice the truth.

6
  • I have URL encoded all of my image reference. What exactly is the benefit of doing this and what are the downsides of not doing it? Commented Oct 18, 2012 at 6:25
  • 1
    It's not just relevant for images, it's always relevant if you want standard conform URIs. The benefit is at a minimum that everything can be crawled, requested or displayed as expected. See also this discussion stackoverflow.com/questions/912811/…
    – initall
    Commented Oct 18, 2012 at 8:16
  • I see. I have URL encoded most of the dynamic elements on my website but left the static ones as they were, given that they are indeed static and thus will never change into an invalid URI. Commented Oct 18, 2012 at 10:29
  • Just thinking... "the bot ... url-decode your references/links" - but does the bot decode the encoded links? The browser does not necessarily decode the links. I think this might depend on which characters are encoded and whether they belong to the reserved set. Reserved characters (of which ! is one) should not be decoded by the browser and is sent to the server as is - the server then decodes the URL. eg. Google Chrome treats "test-1234-!.jpg" and "test-1234-%21.jpg" as 2 separate URLs, both are sent as is to the server as 2 separate requests and both are cached separately.
    – MrWhite
    Commented Oct 18, 2012 at 11:55
  • cont... conversely "test.jpg" and "%74%65%73%74.jpg" (unreserved characters are encoded - not recommended) are treated the same by the Browser (Chrome). The browser does indeed decode the encoded URL and sends only a single request. Both these cases are according to the spec (RFC 3986 as linked to above), but the spec also states that some systems might incorrectly treat all encoded/decoded URLs as different. The moral of the story is to be consistent in your encoding.
    – MrWhite
    Commented Oct 18, 2012 at 12:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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