Optimize your Wordpress site with Rackspace CDN

CDN is abbreviation for Content Delivery Network. Hard to believe that like 5 years ago it sounded like a rocket science in WWW. Only huge sites were able to afford it and configure it right. Now things have completely changed and today's question is: Why you still do not use CDN for your site or blog?

Because of the W3 Total Cache plugin, setting up a CDN for Wordpress based site is criminally simple. Thats another one cent in my love Wordpress topic. If your website receives more than a few hundred visitors a month, or if your site makes visitors download a lot of data (images, self-hosted javascripts, flash files, etc.), this is a great setup.

There’s also an SEO benefit in using a CDN…at least indirectly. Faster sites get more traffic from Google and Bing than slower sites. By making your site faster, you increase the likelihood Google will refer people to your site.

Why wordpress cron fails and how to fix

WordPress has its own cron job implementation that allows you to schedule your posts and events. It was done in a way to be simple and it works in most cases.

WP-Cron is not a real cron job, it only works when a page is loaded. When a page is requested, it will then check the database to see if there is anything scheduled and after displays to your reader.

However, in some situations, the WP-Cron does not work well and this leads to posts that missed publication schedule and events not executed.  May be you have seen the “Missed Schedule” status.

Move wordpress site to new domain issue

Wordpress has a interesting oddity, it stores site path with domain name in its settings in database. If you are moving your WP site, you have to change that setting before! I do not judge is it a good or bad decision, but it works this way.

If you forget to change Siteurl, WP installation won't work on new location. Here is how to fix it!

Using layout pattern with CodeIgniter

CodeIgniter is great framework by its simplicity. But when I moved from CakePHP, I really missed layout pattern.

CodeIgniter documentations offers this way to include non-changing site header and footer

$this->load->view('header');
$this->load->view('template'); 
$this->load->view('footer');

For sure it isn't flexible and does not show page structure in a clear way. For many years I use layout pattern. Layout describes whole page as a template with blocks for header, menu, content, etc like on figure below. On page rendering these blocks are filled with data.

I found a small code snipped for CI and improved it. You are welcome to try!

Marker clusters on Google Map with two data sources

Clustering markers on GoogleMap is a very useful think in case of thousands of markers displayed. It makes the map look nice and fancy, instead of marker mess. In my previous post I told how to use MarkerClusterer library.

Today I want to add some advanced techniq how to use different styles, in case there are several datasources available.

Parse HTML using jQuery-like syntax in PHP

Quite often there is a need to parse HTML and extract some values from deep-deep nested tables or so. Most front solution is to use regular expressions but they sucks with nested tags. Other way is to use XPath, which performs much better here, but has not simple syntax to use.

Nowadays almost all PHP developers knows jQuery, which became like a standard in front-end development. Why not to use it for HTML parsing using familiar syntax.

Handling expired sessions in AJAX applications with jQuery

Nowadays quite lots of sites are AJAXy, especially their back-end part. This introduces one interesting issue with sessions and password protected areas.

Typical scenario is: password protected URL initiates a server-side check for valid user is logged in or in other case redirects to login page.

What happen when session is expired by timeout? Session data is wiped from the server, so already logged user becomes like a just comer. Next request to the server will eventually redirect him back to login dialog.

But not in case of AJAX. Usually AJAX requests are written in the way not to support sudden session break and this situation can lead to a very unpredictable behavior. How to fix it quick?

Scale images to FIT/FILL bounding box in PHP using GD

Quite often I was in need a function to scale an image to the size right to fit into bounding box.

For example, displaying images of real estate or product image in the shop site. Images can be different sizes, less or bigger of target size, portrait or landscape, etc..

I wrote little helper function in PHP that does that tasks using two modes: FIT and FILL. It uses standard PHP-GD extension.

Handling huge amount of markers on Google Maps with clusters

If you used Google Maps in your projects as a developer,  probably you faced with a problem to display huge amount of markers on the map. Problem seems more User Interface related, than technical. On small zoom it does not look good. I solved it using a very nice marker clustering library available from Google.

What is jQuery .live() event handler

If you did not face with .live() handler before, this post is probably for you!  It makes event handling code much cleaner and easier to use on heavily dynamic pages.