Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I did something that does that when people land on my page for the first time, they get a JavaScript redirection to the same page, but with PHP $_GET URL queries, then this page redirect back to the page without these queries, so the server got the screen's size of the client during this process.

The thing is that this redirection is done in JavaScript client-side, so I wonder if it could hurt my website's SEO in some ways (continue reading).

Here are solutions that I think could be good, but I'm not sure about what to do and what will happen if I do that. I don’t really know how Google scan sites, so I may be wrong:

  • Should I put this JavaScript redirect at the bottom of my page's code, so Google will have the time to scan my entire page before being redirected?

  • Should I put this JavaScript code in the <head> of the page so that there will be no waiting before the redirect is done, so human clients will be satisfied to not have to wait some milliseconds more, but Google will scan the second page instead of the first, or will incompletely scan the first?

  • Should I detect with PHP whether or not I should echo this JavaScript code based on the type of the visitor (human or not). If this is what I should do, how to do it simply?

This is important, as this JavaScript code is on each page and is echoed in PHP each time someone (or a robot) visits the site for the first time.

share|improve this question

migrated from stackoverflow.com Jul 29 '13 at 12:36

This question came from our site for professional and enthusiast programmers.

    
Google bot doesn't understand javascript so don't worry, it wont be redirected –  Ahmad Jul 27 '13 at 19:39
    
Could google evolve in the next years and understand Javascript? –  Che Jul 27 '13 at 19:44
1  
Its not proposed at this moment, I wouldn't event think about it. Javascript is a client side language that runs on client's browser to change the behaviour of the document, I don't think search engine bots will ever need to support such thing. –  Ahmad Jul 27 '13 at 19:46
3  
Google can and does recognise javascript redirects and can in fact parse JS. –  sovarn Jul 28 '13 at 15:59

2 Answers 2

up vote 2 down vote accepted

Your solution here is very misguided for several reasons, mainly that the user's browser must make not one, but three separate requests for the same page. That's tripling your traffic and greatly slowing down the user. You are also passing information back and forth many times between PHP and JavaScript which you simply do not need to do.

If you are showing images in a "lightbox" style popup on the page then there is no need for any server-side interaction at all. JavaScript can detect the browser width and request a different image instead.

Perhaps you would be better off looking for a pre-built lightbox plugin. Just search for "JavaScript lightbox plugin" and you will find hundreds of different ones. Many of them include an explicit "showImage" function, so you can attach a click event handler to the link/thumbnail, and in that handler check the screen width and either open the image directly or call the lightbox plugin.

share|improve this answer

Google can parse JavaScript and may view this weird behavior as deceptive. I can't say for sure if this is the case but by allowing Google to go through two redirects it may also create duplicate content.

If you really need to get the screen width why don't you just use JavaScript to get it?

<script type="text/javascript">
    document.write(screen.width+'x'+screen.height);
</script>

This is also probably the most user friendly way of dealing with this problem as the user will not have to spend time going through needless redirects.

share|improve this answer
    
I needed to have this information in PHP to know what link to echo when opening an image to make it bigger in a frame over the page. Could a JS code do that with an if/else ? E.g. if the screen is larger that 1800px, write a link with ?large=true at the end of the url. Else, write a link with this query variable on false at the end of the URL. It will also depends of which JS file I will include in my <head> to open the frame. I'm not really good with JS and most of the things I do with it got coded by someone else, so I find that sending these infos to PHP is more simple. –  Che Jul 28 '13 at 20:55
    
And these links, that it be the large with true or false, would need to be recognized by google for SEO, but they are a bit less important as they are just pictures with keywords. –  Che Jul 28 '13 at 21:02
    
You can use jQuery to detect the screen width, and if wider than 1800 then just use a modal window to display a certain image. All this can and probably should be done in javascript for best user experience. –  sovarn Jul 29 '13 at 2:21
1  
You can also check the HTTP Header User-Agent value on the server side to get an idea on what device is making the requests. Or use the css media type to hide/show different versions of the images. Or have JavaScript dynamically set image URLs. All better than looping the user around. –  Tiggerito Jul 29 '13 at 14:35

Your Answer

 
discard

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.