Query Optimization At Front-End
- July 21, 2015
- Leave a comment
In order to make your page faster, you need to eliminate Notices and Warnings from your website. These notices are generated when your code runs a query that uses a variable which is either not defined or is empty. These notices won’t crash your page but they’ll surely make your website a bit slower. We can use a couple of plugins in order to get rid of these notices and make your site faster.
You can visit any page of your website which you want to analyze on the front end. On that page, If you click on Debug it will show you the complete detail of queries that are being used on that page like time consumed by each query, Notices on that page, Warnings and even queries that are taking too much time to execute. Now you have a complete and short analysis of your web page and its performance.
Every developer has a different approach to resolve such optimization issues. Also, the nature of errors and notices is going to be different for different websites/themes.
In order to fix these issues, you’ll have to analyze them individually. But in general, most of these notices are generated because of empty or undefined variables. In order to make sure that you don’t get these errors, use a condition as a precaution before each query where you check that variable is defined and it has some value. For example:
NOTICE: wp-content/themes/yourthemename/functions.php:277 – Undefined variable: $data
Here “$data” is an array which contains settings saved from theme options from admin panel. You might get this error because previously someone might try to use an index of this array but didn’t define it. To resolve this issue, you only need to define it before “$data” was used in code.