Hide Javascript From Search Engines

Discussion in 'PHP' started by minnseoelite, Nov 30, 2006.

  1. #1
    I was just wondering I know that search engine cannot read javascript and having it on ones pages ruins the pages code to text ratio. I use PHP includes for all my javascript files and was wondering if there is a way to make it so that the javascript shows up on my pages for my visitors but is not visible to search engines.
     
    minnseoelite, Nov 30, 2006 IP
  2. skionxb

    skionxb Peon

    Messages:
    376
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Why don't you just place it in the external javascript.js file?
     
    skionxb, Nov 30, 2006 IP
  3. minnseoelite

    minnseoelite Peon

    Messages:
    845
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #3
    will that hide all the code from search engines and would that look something like this. Sorry not much of a programmer.

    <? include("javascript.js"); ?>
     
    minnseoelite, Nov 30, 2006 IP
  4. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
    #4
    PHP is not needed for this. Move your js code to the dedicated file and include it in HTML like this:

    <script type="text/javascript" src="jscode.js"></script>
    HTML:
     
    wmtips, Nov 30, 2006 IP
  5. minnseoelite

    minnseoelite Peon

    Messages:
    845
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #5
    ok but the reason i was asking is because the same script will be used in 3 or 4 different places on the same page so i guess i need to know what is the code to use for the actual placement of the javascript so it appears where i want it to on the page.
     
    minnseoelite, Nov 30, 2006 IP
  6. minnseoelite

    minnseoelite Peon

    Messages:
    845
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #6
    this thread is related to SEO not PHP that is just the language I was using at the time could a Mod change it back
     
    minnseoelite, Nov 30, 2006 IP
  7. KC TAN

    KC TAN Well-Known Member

    Messages:
    4,792
    Likes Received:
    353
    Best Answers:
    0
    Trophy Points:
    155
    #7
    To answer your question, JS script only loads on the client side (external file inclusion) and it will not be visible to the bots :)
     
    KC TAN, Dec 1, 2006 IP
  8. minnseoelite

    minnseoelite Peon

    Messages:
    845
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #8

    yes but it appears in the sites code which means it can be viewed by bots. an i know google can see it cause according to google sitesmaps they tried to spider and external link from one of the kanoodle ads which in return generated a 404 error.
     
    minnseoelite, Dec 1, 2006 IP
  9. Slincon

    Slincon Well-Known Member

    Messages:
    1,319
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    180
    #9
    google doesn't pull images or external stylesheets or javascript. So unless your external javascript file was linked to directly with href links, it won't be spidered.
     
    Slincon, Dec 2, 2006 IP
  10. crazyden

    crazyden Guest

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    If you are afraid of code, used in different places, make JS function, but you must include external JS file, not embed it to your HTML
     
    crazyden, Dec 3, 2006 IP
  11. minnseoelite

    minnseoelite Peon

    Messages:
    845
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #11

    Not affraid of code just wanting to try it for something different as an experiment with the sites rankings.
     
    minnseoelite, Dec 4, 2006 IP
  12. crazyden

    crazyden Guest

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    You know, I do not think that Kava Script will really affect you site rank, at least if it will, then it will be the last criteria
     
    crazyden, Dec 13, 2006 IP
  13. Krownet

    Krownet Peon

    Messages:
    42
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #13
    JavaScript in the file shouldn't effect page rank or readability by the search engine (especially Google). Getting query strings out of URLs and building content is what's really important. Also getting links on higher PR sites than you, increases your PR (so I've heard).

    Cheers,
     
    Krownet, Dec 14, 2006 IP
  14. GTech

    GTech Rob Jones for President!

    Messages:
    15,836
    Likes Received:
    571
    Best Answers:
    0
    Trophy Points:
    0
    #14
    If I understand your request, you want to display javascript *only* if it's a normal user and *not* if it's a search engine bot.

    If that understanding is correct, you can add the following function to your PHP functions:

    
    <?
    function check_search_engine() {
      if (!isset($_SERVER['HTTP_USER_AGENT'])) {
        $user_agent = '';
      } else {
        $user_agent = $_SERVER['HTTP_USER_AGENT'];
      }
    
      $search_engines[] = 'Fast';
      $search_engines[] = 'Slurp';
      $search_engines[] = 'Ink';
      $search_engines[] = 'Atomz';
      $search_engines[] = 'Scooter';
      $search_engines[] = 'Crawler';
      $search_engines[] = 'bot';
      $search_engines[] = 'Genius';
      $search_engines[] = 'AbachoBOT';
      $search_engines[] = 'AESOP_com_SpiderMan';
      $search_engines[] = 'ia_archiver';
      $search_engines[] = 'Googlebot';
      $search_engines[] = 'UltraSeek';
      $search_engines[] = 'Google';
    
      foreach ($search_engines as $key => $value) {
        if ($user_agent != '') {
          if(strstr($user_agent, $value)) {
            $is_search_engine = 1;
          }
        }
      }
    
      if (isset($is_search_engine)) {
        return TRUE;
      } else {
        return FALSE;
      }
    }
    ?>
    
    Code (markup):
    So that it's always accessible to your php pages, then wherever you want to conditionally insert your javascript code (for users only and not search engines), you could use something like:

    
    <?
    if (!check_search_engine()) {
      <? include("javascript.js"); ?>
    }
    ?>
    
    Code (markup):
    Hope that helps.
     
    GTech, Dec 14, 2006 IP
  15. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
    #15
    It is called cloaking. I would not recommend to provide different content for users and SEs, by doing this you could be penalized.
     
    wmtips, Dec 14, 2006 IP