April 13, 2013

Improving the performance of the Drupal Simpleads module

Filed under: Tips,Web Content Pages — Tags: , , — Webopius @ 8:08 pm

Drupal 7 incudes the fantastic SimpleAds module allowing easy creation, management and tracking of Image and Banner ads within your Drupal website.

SimpleAds works really well but uses Javascript to render the ads once the page is displayed which can sometimes result in a 1 or 2 second delay before you see the ads appear on the page. This can give the impression that the page is loading slower than it actually is.

The rationale for using Javascript is that is remains unaffected by block level caching within Drupal so that if you update Ads, those updates will always appear immediately rather than waiting for the cache to expire.

If you want much faster loading ads and are happy for changes to ads to appear to end users once your “Expiration of cached pages” setting is reached, then this is the solution for you…

How to improve the performance of SimpleAds loading…

Edit the file:

simpleads_block.tpl.php (usually within your sites/all/modules/simpleads/templates directory)

Comment out the Javascript _simpleads_load() function call at about line 48:


// _simpelads_load('.simpleads-<?php print $tid; ?><?php if ($prefix) : ?>-<?php print $prefix; ?><?php endif; ?>', <?php print $tid; ?>, <?php print check_plain($ads_limit); ?>);

Now, add in the following lines within the <div class=”simpleads-…” block below

<?php $nodes = _simpleads_load_ads($tid, $ads_limit); ?>
<?php print _simpleads_render_ajax_template($nodes, $tid, $ads_limit); ?>

The php code lines below this should remain commented out.

Now reload a page containing ads and look at the performance improvement!

  • Tags