Recently, I have had the following dilemma:
I am using a PHP function that generates a QR image associated with the current URL, which is very useful for mobile devices. The function works fine, but having my site on shared hosting, there are some restrictions on the use of CPU and RAM. This feature is heavy, and it consumes a lot of processor time and RAM, so the hosting guys asked me to reduce the use.
After some attempts, I finally got to the idea that I can save CPU and RAM from bots in search engines. It is difficult to recognize the bot by browser ID, but all the bots do not have JS, and what are the main criteria that I used to determine if it is a real browser or is it a bot. To explain how important it is to prevent the execution of code that will not work for search engines (QR, in my case, does not affect search engines), I can say that only the Google bot, for example, is about 16,000 crawls per day on my site.
So, I did a very simple thing that really helped:
<script language="javascript"></script>
This code uses JS to write a line of PHP code, so this line will only be written with JS enabled.
From couse, you can use the "noscript" tag if you want to show something when JS is disabled, but this method shows how to execute some PHP only with JS enabled.
Hope this helps.
Reflective Sep 20 '12 at 17:01 2012-09-20 17:01
source share