In the Top Sites section of Safari, the iCloud.com image shows the logo instead of the login screen as you can see below. Normally, the Top Sites just shows a picture of the loaded web page (and the loaded page does not look like this). Do you have any idea how they accomplished this? I couldn't find anything in Apple's documentation. Thanks for your help.
-
There is something I don't understand: the goal of the bounty was to have a better answer than the one from Phil and with more details. Then why did you offered the bounty to Phil and not to me? – Alexandre Khoury Jun 20 '12 at 19:59
-
@Mageek I'm sorry, I started the bounty BEFORE Phil answered since none of the answers given were correct. I really appreciate your answer, but Phil answered first. I gave you an up vote. – Jack Humphries Jun 20 '12 at 20:03
-
Did you wait until the end of the bounty? – Alexandre Khoury Jun 20 '12 at 20:05
5 Answers
Here's how it's done on iCloud to show a Top Sites specific preview: (edited for formatting)
if (window.navigator && window.navigator.loadPurpose === "preview") {
window.location.href = "http://www.icloud.com/topsites_preview/";
};
Source: http://blog.raffael.me/post/18565169038/defining-how-your-website-looks-like-in-safari-topsites

- 1,288
- 1
- 10
- 19
-
+1 'cause it all makes sense. I also checked and this script is at the top of icloud website. It's enough to create under `topsites_preview/` preview template and all should work. Thanks Phil ;) – Sófka Jun 18 '12 at 08:00
In fact, Safari doesn't search a <link>
tag or anything else. There is two dfifferent thing that we can use:
The HTTP headers of the incoming request in PHP.
The properties of the
window
object in JavaScript.
The two ways work very good and you can use any of them, or even both of them if you want to be sure.
PHP:
If we inspect the HTTP headers, we will see that when it's Safari Top Sites Preview that sends the request, there is X_PURPOSE
that is set to preview
. Then you must write in the normal website:
if($_SERVER["HTTP_X_PURPOSE"]=="preview")
{
header("Location:thumbnail link");//Redirect to the thumbnail.
}
//Display the normal website.
And you can add in the page where there is the thumbnail:
if($_SERVER["HTTP_X_PURPOSE"]!="preview")
{
header("Location:normal link");//Redirect to the normal website.
}
//Display the thumbnail.
So that you can't see the thumbnail except from the Safari Top Sites Preview.
JavaScript:
window.navigator.loadPurpose
has the value preview
if it's Safari Top Sites Preview which tries to open the website. But window.navigator
does not exist if it's in a normal view. As such, when you test this value, you have to test for the very existence of this property as well as for its truthiness. Then this is the code for the normal website:
if(window.navigator&&window.navigator.loadPurpose==="preview")
{
window.location.href="thumbnail link";//Redirect to the thumbnail
}
And for the thumbnail page:
if(!window.navigator||window.navigator.loadPurpose!=="preview")
{
window.location.href="normal link";//Redirect to the normal website
}
Little trick from me:
If you really want to put a <link>
tag you can write:
<link rel="safari-preview" href="thumbnail link" />
And then add at the end of the head section:
<script>for(var i=0,link=document.getElementsByTagName("link"),l=link.length;i<l;i++)if(link[i].getAttribute("rel")==="safari-preview"&&window.navigator&&window.navigator.loadPurpose==="preview")window.location.href=link[i].getAttribute("href");</script>
Sources:

- 3,896
- 5
- 37
- 58
-
Do you know if Chrome uses the same technique to fetch previews of the most popular pages? – Simon Jan 17 '14 at 09:36
-
I believe they programmatically grab a snapshot of the page when it's finished loading. And if you look at the progress bar at the top, when iCloud shows that (just the iCloud logo), it's finished loading and is doing a little animation.

- 1,935
- 5
- 23
- 37
-
The website never shows JUST the logo though and it's never that size. – Jack Humphries Jun 15 '12 at 21:05
I think that they made it especially for their iCloud service, they just check if the domain is the icloud domain and if it is they show this logo instead of the normal site preview.

- 4,974
- 5
- 27
- 39
Apple touch devices can look for precomposed images on your webserver. I know it can query for these images:
- apple-touch-icon-114x114-precomposed.png
- apple-touch-icon-144x144-precomposed.png
- apple-touch-icon-57x57-precomposed.png
- apple-touch-icon-72x72-precomposed.png
If you check out the souce of iCloud.com you will notice it will have <link />
elements pointing to these resources too (because they're not in the root):
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="/system/cloudos/en-us/1JPlus21/source/resources/images/apple-touch-icon-114x114.png">
I'm just guessing here but maybe safari looks for the same images to show in the top sites view.
More on these types of images can be found here
http://theksmith.com/technology/howto-website-icons-browsersdevices-favicon-apple-touch-icon-etc/

- 9,411
- 3
- 36
- 52
-
Lately, I made some sites with attached iPhone icons, so if you're answer would be right, instead of printscreen I should get special icon, but after adding site to top sites, I got nothing else but still printsreen of my site. So I think it's something else or something more. – Sófka Jun 18 '12 at 07:52
-
@Sófka looks like Phil figured it out (if it works) I was just guessing after all :) – sg3s Jun 18 '12 at 08:06
-
Yep ;) I checked this theory 'cause it was interesting ;) It's always a good thing to try! Cheers ;) – Sófka Jun 18 '12 at 08:12