Resolve jQuery and MooTools Conflict

January 24th, 2010 10:30 am by John Dalesandro No comments

jQuery and MooTools are great JavaScript libraries for introducing dynamic interactions to your web site or application. They both include capabilities for manipulating CSS and adding various effects and animations as well as pre-built Ajax functions. However, if you need to use both on the same page then you’ll immediately have a conflict since they both use the same namespace by default. To avoid the conflict, jQuery includes the ability to modify its namespace using jQuery.noConflict(). If you call this method after loading the jQuery library, then all references to jQuery should use “jQuery” instead of “$.” This will allow MooTools to function using $. The particular issue I had was a conflict between jQuery, Thickbox and MooTools. Correcting this conflict required the additional step of changing all references to $ in the Thickbox library to jQuery. Thickbox includes some uses of $ that shouldn’t be replaced, so don’t do a global find and replace.

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
  jQuery.noConflict();
</script>
Categories: Computing Tags: , ,

Preventing Referrer Spam

January 24th, 2010 9:30 am by John Dalesandro No comments

There is a plugin called Bad Behavior for WordPress that helps reduce referrer spam. As long as your log files are properly secured and not publicly available, then referrer spam isn’t much of a problem. However, if you’re like me and you don’t prefer links to nasty sites showing up in your StatPress dashboard, then Bad Behavior might be a plugin worth adding to your site. This site uses a combination of both Bad Behavior and WP-SpamFree which seems to catch almost all of the spam hits and comments. I don’t receive a lot of traffic so I can’t tell how this combination would work on a high volume site. As a minor warning, these plugins do seem to slow down response time just a bit.

Categories: Computing Tags: , ,

Disable All Links Within DIV

December 14th, 2009 5:00 pm by John Dalesandro No comments

This JavaScript function will disable all links within the specified DIV by setting the link object to ‘disabled’ as well as removing the ‘onclick’ and ‘href’ attributes. This is a useful JavaScript function for form submissions since it will help prevent the user from clicking another link while an action is pending.

function DisableAllDIVLinks(DivId) {
  var div = document.getElementById(DivId);
  var anchorList = div.getElementsByTagName('a');
 
  for(var i = 0; i < anchorList.length; i++) {
    anchorList[i].disabled = true;
    anchorList[i].onclick = '';
    anchorList[i].removeAttribute('href');
  }
}
Categories: Computing Tags: ,

Performance Tuning Tip #2 – Process Data In The “Right” Layer

September 7th, 2009 12:00 pm by John Dalesandro No comments

Tip 2: Process Data In The “Right” Layer

I find that it is almost always faster to process data within the DBMS rather than sending the raw result set back to the application layer and iterating / processing each row individually. A DBMS is specifically designed to handle sets of data. Do as much of the processing in the DBMS before returning the result set to the application layer. You may be able to do the processing in another layer, but ask yourself “Is it the most appropriate?”

Performance Tuning Tip #1 – Optimize The Query

June 23rd, 2009 8:00 pm by John Dalesandro No comments

Tip 1: Optimize The Query

In my opinion, the first and most important step in performance tuning an application is to optimize the underlying query. If you have a slow query or a query that returns too much data, then the downstream processing will have a negative performance impact regardless of any optimization used in those subsequent steps.

  • Minimize the number of columns returned by the query by using named columns instead of SELECT *. Are all of the columns from all of the joined tables truly needed?
  • Add the appropriate constraint clauses to your query so that the returned data set is reduced to the right size.

If your operational data set is too large, i.e. you don’t need the data, then don’t return it. This will help improve downstream performance by limiting the amount of data processed by the DBMS and subsequently transferred over the network between the database and application layers.

  • Use data aggregation functions in the query. If the data can be consolidated through summation or other aggregation techniques, this will help reduce the data set by returning one row instead of many.
  • Identify opportunities to eliminate zero based row data. Depending upon your application requirements, it may not be necessary to return rows with zero or null data elements.
  • Provide query hints to the DBMS. In some instances, it may be beneficial to assist the built-in query optimizer when the DBMS generates the execution plan. The optimizer does its best to generate the optimal execution plan, but sometimes the developer knows best.