Title: [Plugin: Dave&#8217;s WordPress Live Search] Few optimisations
Last modified: August 19, 2016

---

# [Plugin: Dave’s WordPress Live Search] Few optimisations

 *  [criography](https://wordpress.org/support/users/criography/)
 * (@criography)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/plugin-daves-wordpress-live-search-few-optimisations/)
 * While developing my own site and making modifications to the way search results
   were displayed (sorted by categories e.g.) I noticed the way some of the things
   in ‘daves-wordpress-live-search.js.php’ were coded.
 * I believe it’s much faster to start with:
 *     ```
       function LiveSearch() {
          var results='';
       }
       ```
   
 * and then assign this element (with id rather than class) once for all so you 
   don’t have to search for it ever again. I’m actually appending it to a css positioned
   element and by doing that I don’t have to dynamically calculate search results
   left and top coordinates – adding few lines of static css does the trick. Also
   rather than having click event binded to every existing element in your DOM, 
   just bind it once to your body.
 *     ```
       LiveSearch.init = function() {
          LiveSearch.results=jQuery('<ul id="search_results"></ul>').appendTo("#sideBar").hide(); 
   
       (...)
   
       jQuery('body').click(LiveSearch.hideResults);
       jQuery('#s, #search_results').click(LiveSearch.handleClicks);
       }
       ```
   
 * Then simply reduce handleClicks to:
 *     ```
       LiveSearch.handleClicks = function(e) {
       	var target = jQuery(this);
       	e.stopPropagation();
       };
       ```
   
 * get rid of all dynamic positioning and obviously replace all instances of ul.
   search_results with existing variable. It renders slightly faster expecially 
   in IEs and the code is cleaner (:
 * Otherwise great plugin!
 * [http://wordpress.org/extend/plugins/daves-wordpress-live-search/](http://wordpress.org/extend/plugins/daves-wordpress-live-search/)

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Dana Ross](https://wordpress.org/support/users/csixty4/)
 * (@csixty4)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/plugin-daves-wordpress-live-search-few-optimisations/#post-1270157)
 * OMFG criography, that’s the kind of in-depth attention this plugin has been needing.
   I’ll take a closer look at your changes this week (hopefully) and integrate them.
   I’m planning for a 2.0 release by the end of the year, and this would be a great
   way to start things off.
 * – Dave
 *  [Dana Ross](https://wordpress.org/support/users/csixty4/)
 * (@csixty4)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/plugin-daves-wordpress-live-search-few-optimisations/#post-1270219)
 * handleClicks can actually be one line shorter at that point, as we don’t need
   that target variable anymore.
 *  [Dana Ross](https://wordpress.org/support/users/csixty4/)
 * (@csixty4)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/plugin-daves-wordpress-live-search-few-optimisations/#post-1270220)
 * Screw it, handleClicks has been replaced with a closure passed to click(). Goodbye,
   old friend.
 *  [Dana Ross](https://wordpress.org/support/users/csixty4/)
 * (@csixty4)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/plugin-daves-wordpress-live-search-few-optimisations/#post-1270222)
 * I made most of the changes you recommended. I’m still on the fence about getting
   rid of the dynamic positioning. I can certainly do something with CSS, but the
   point of doing it that way was to eventually be able to ditch the requirement
   of only having one search box on the page.
 * I’d actually like to get that working at some point, although it doesn’t affect
   many themes. Go ahead & grab the latest development version if you want and let
   me know how it performs for you.
 * Thanks again!
    Dave

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘[Plugin: Dave’s WordPress Live Search] Few optimisations’ is closed to
new replies.

 * 4 replies
 * 2 participants
 * Last reply from: [Dana Ross](https://wordpress.org/support/users/csixty4/)
 * Last activity: [16 years, 6 months ago](https://wordpress.org/support/topic/plugin-daves-wordpress-live-search-few-optimisations/#post-1270222)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
