This ColdFusion Optimization guide is a work in progress document based on research and experience.
Boolean variables will only work reliably in conditional statements if their value equals "true", "false", 1, or 0. Type coercision from 1 or 0 is not consistent, so check against "not false" or "GT 0" explicitly.
Use cfswitch instead of cfelseif branches
Use cflocation with a reference to a serialized data file or URL parameters to pass data from an action file to a display file instead of cfinclude. This will redirect the browser and append the action page to the browser history. This prevents multiple attempts to update to the database if the user refreshes the display page, which would occur if a cfinclude was used.
Immediately read, parse, and delete uploaded files after inserting validated data into the database to prevent DOS attacks
Use
Do not add a trailing slash in the definition of the configuration parameter in application.cfm such as the document root or a base URL, since it is easier and more readable to use a slash after referencing the variable, and will prevent double slashes from causing path not found errors.
Use Len(CGI.xyz) GT 0 instead of IsDefined("CGI.xyz") to check whether the length of a CGI parameter is greater than 0 instead of checking for its existence, since different Web servers support different CGI environment variables, and CGI.xxx is always defined, regardless of its value
Limit concurrent updates to the database using CFTRANSACTION, not CFLOCK. CFTRANSACTION
will affect all accesses to the data being updated, not just those occurring in your ColdFusion code.
Use IsNumeric to distinguish between the number zero and an empty string for type checking conditional statements
Use a blank onrequestend.cfm to pair with application.cfm and speed up processing
Put cfoutput tags outside of loops to avoid unnecessary processing overhead
Use the maxrows attribute in cfquery tags when retrieving a known number of rows
Use init methods for components to pass in default values for public parameters that will be used in multiple methods
Use cfscript to initialize a group of variables instead of multiple cfset statements
Use the length function instead of isdefined to check for existence
Check for existence to avoid initializing variables more than once
Always use cfargument in component definitions and specify whether the required attribute is true or false unless a default value is expected
Use structKeyExists(arguments, "arg_name") to test for the defined arguments with no default or required value
Always define an init method for components and set var scope for cfc variables
Include the encoding description
Use compareNoCase(string1, string2) NEQ 0 instead of string1 IS NOT/NEQ string2
Use listFind instead of the OR operator
Use len or isdefined with a scope specified to check for the existence of variables
Put series of string or numeric data in an array instead of a list for operations other than loops
Always use cfqueryparam and blockFactor(calculated by: 3200/ total byte size of one row) in cfquery tags
Never use the evaluate, incrementValue, or iif functions
Use struct[key] instead of structFind(struct, key)
Use the val() function to ensure the validity of a number before inserting it into a database
Use the trim() funtion to remove whitespace from a string before inserting it into a database
Use a cfc, cfimport, cfinclude, or custom tag instead of the cfmodule tag
Use cfsavecontent instead of the cfcache tag to cache dynamic content
Use XML, SOAP, REST or XSL instead of wddx
Use cookies and URL parameters instead of passing local variables to check the state
Never use pound symbols on variables inside of a cfset, cfif, or cfscript tag
Use query of queries to loop or join cached queries. This enables pagination without multiple database queries. Check session or cookie authorization when accessing cached data
Use cflock when setting application or session variables
Use session-scoped locks for session variables and named locks for application and server variables.
Initialize global component objects once as application variables using the Singleton pattern instead of creating new instances for each part of the application
Use custom tags for reusable UI widgets, closures, and recursive code that generates dynamic content
Use cfincludes for page specific code that needs to reference application and local scope parameters implicitly
Use components for secure domain specific data, web services, encapsulating business logic, and sharing common functions through a single library
Use user defined functions for complex algorithms and procedures that can be used in multiple instances. Read More...
More Information visit ColdFusion Development Services.
Post a Comment