Caching Question
Permalink
Hi All,
When active the full page cache is incredible fast for my website pages. The issue I have is that i have a block at the header of my page that has a banner advert in. When loaded this block inserts an impression count into the database.
In order for this to work i have to update the Blocks '$btCacheBlockOutput' and set it to false. This then adds the impression int the database on page load. However it stops the full page cache from working.
Can someone suggest a better method of achieving this that will allow me t enable the full page cache and still record the impression in the database without using an iframe..?
Thanks
When active the full page cache is incredible fast for my website pages. The issue I have is that i have a block at the header of my page that has a banner advert in. When loaded this block inserts an impression count into the database.
In order for this to work i have to update the Blocks '$btCacheBlockOutput' and set it to false. This then adds the impression int the database on page load. However it stops the full page cache from working.
Can someone suggest a better method of achieving this that will allow me t enable the full page cache and still record the impression in the database without using an iframe..?
Thanks
Thanks, No it is a custom b;lock that i have created myself, so I will need to create a custom template.
Also will this only work if i force the entire page to cache..? Can i not just set full page caching to on (only where blocks permit), or does it have to be forced on each page to work..?
Also will this only work if i force the entire page to cache..? Can i not just set full page caching to on (only where blocks permit), or does it have to be forced on each page to work..?
Also to follow up.. if i create a new template, surely my block will run through the controller first and action all he scripts in here before it moves onto the view.php instance of the custom template..?
If thats the case it will not prevent the block from not running before the page has finished loading.
Or am i way off here..?
If thats the case it will not prevent the block from not running before the page has finished loading.
Or am i way off here..?
The way Blocks By AJAX works is to load some Javascript and a placeholder when the block is rendered on a page. The javascript is then triggered (variety of triggers) and re-loads the block from a c5 tool file. In the tool file, a flag is passed that tells Blocks by AJAX to render the full view of the block.
For most blocks, this involves a template that says:
Creating such a template is straight forward. However, if you don't want to, you can put the block in a stack and then load the stack with a Blocks by AJAX template (there are ajax templates for Stack Randomizer and for Universal Content Puller)
On the scripts part, yes, that is correct. So some blocks that are only script files loaded by the controller and are not initialised by a js call from the view will not work without modification. However, the vast majority of complex javascript blocks will load through Blocks by AJAX with no modification.
If you want me to test a copy of your block, zip it up with all scripts etc needed for it to run and PM it to me. I will run it on a development system with an ajax loaded stack and let you know if it will work, if it won't or if it will work with modification (and what).
For most blocks, this involves a template that says:
if (regular_view){ render ajax loader script } else { render normal block view }
Creating such a template is straight forward. However, if you don't want to, you can put the block in a stack and then load the stack with a Blocks by AJAX template (there are ajax templates for Stack Randomizer and for Universal Content Puller)
On the scripts part, yes, that is correct. So some blocks that are only script files loaded by the controller and are not initialised by a js call from the view will not work without modification. However, the vast majority of complex javascript blocks will load through Blocks by AJAX with no modification.
If you want me to test a copy of your block, zip it up with all scripts etc needed for it to run and PM it to me. I will run it on a development system with an ajax loaded stack and let you know if it will work, if it won't or if it will work with modification (and what).
Thanks, I have PM'd you.
I got the block installed (some specifics in the reply PM).
- I added the block to a stack and ajax loaded the stack to a page with no problems.
- I quickly created a Blocks By AJAX template for the block, added the block to a page and assigned the ajax block template. All loaded with no problems. (I have sent you the template with the PM reply)
- I set full page caching always, logged out, loaded the page (instant with full page caching) and the block ajax loaded with no problems.
- I clicked the ad and the link worked. I used phpMyAdmin to check the click through count table ptBannerAdClicks and the clicks are incrementing correctly.
- Repeated several times and watched the clicks increment.
For accurate counting, it will be necessary to move the call to generate impression from the block controller into a callback in the block view. That way, impressions will only be counted on the ajax load of the block view. For efficiency, you could also move much of the view() processing into the same callback.
eg in the view:
Where get_banner_info_and_generate_impression() extracts all the info needed and returns it as an array or object, also recording the banner impression.
(I have **not** made such changes in the returned zip)
In summary, should you decide to go this route, there are no incompatibilities between Blocks by AJAX and the current banner block. Some minor changes to the way the block is coded will enable you to record accurate impression statistics. Clickthrough statistics are already accurate.
- I added the block to a stack and ajax loaded the stack to a page with no problems.
- I quickly created a Blocks By AJAX template for the block, added the block to a page and assigned the ajax block template. All loaded with no problems. (I have sent you the template with the PM reply)
- I set full page caching always, logged out, loaded the page (instant with full page caching) and the block ajax loaded with no problems.
- I clicked the ad and the link worked. I used phpMyAdmin to check the click through count table ptBannerAdClicks and the clicks are incrementing correctly.
- Repeated several times and watched the clicks increment.
For accurate counting, it will be necessary to move the call to generate impression from the block controller into a callback in the block view. That way, impressions will only be counted on the ajax load of the block view. For efficiency, you could also move much of the view() processing into the same callback.
eg in the view:
$banner_info = $controller->get_banner_info_and_generate_impression();
Where get_banner_info_and_generate_impression() extracts all the info needed and returns it as an array or object, also recording the banner impression.
(I have **not** made such changes in the returned zip)
In summary, should you decide to go this route, there are no incompatibilities between Blocks by AJAX and the current banner block. Some minor changes to the way the block is coded will enable you to record accurate impression statistics. Clickthrough statistics are already accurate.
Thanks I will buy now and give it a ago
Hi,
I have bought the addon.
I have dropped the new template in which now appears to make the block load via ajax. However i do not want any loading animation. And I have also tried putting the controller callback into the view.php as you have suggested but it is not recording impressions..?
Are you abel to update the custom template please and advise what changes need to be made to the controller as suggested..?
Thanks
I have bought the addon.
I have dropped the new template in which now appears to make the block load via ajax. However i do not want any loading animation. And I have also tried putting the controller callback into the view.php as you have suggested but it is not recording impressions..?
Are you abel to update the custom template please and advise what changes need to be made to the controller as suggested..?
Thanks
You can change or remove the loading animation by either setting a config constant or adding a 'Blocks by AJAX Remote Control' block before the block that is ajax loading.
As you want these settings site wide, I suggest using a constant in config/site.php, or alternatively in your package controller's on_start() handler.
I will have a quick look at the block code needed for the callback and send by PM.
As you want these settings site wide, I suggest using a constant in config/site.php, or alternatively in your package controller's on_start() handler.
define ('BLOCKS_BY_AJAX_DEAFAULT_THROBBER', 'none');
I will have a quick look at the block code needed for the callback and send by PM.
You should receive some revisions to your files by PM. The block controller no longer needs a view() method as all the work is now in the callback made when the block is viewed, either directly or in an ajax template.
I have tested the ajax template and records are being added to ptBannerAdImpressions each time the page is viewed, even when cached.
I only made the minimum changes needed get it working. I expect that having seen how this fits together you will have your own ideas on refining the process further and what is needed to do similar for your other blocks.
I forgot to mention in the previous post that as well as no loading throbber, you can also specify a small throbber or a custom throbber.
Another trick you can apply is to use Blocks By Ajax on a timer to reload adverts every XX seconds, thus facilitating swapping ads while a visitor sits on a page. To do that you would obviously need to add some random picking option to your block and then make the random pick from the list of adds in the callback from the view.
I have tested the ajax template and records are being added to ptBannerAdImpressions each time the page is viewed, even when cached.
I only made the minimum changes needed get it working. I expect that having seen how this fits together you will have your own ideas on refining the process further and what is needed to do similar for your other blocks.
I forgot to mention in the previous post that as well as no loading throbber, you can also specify a small throbber or a custom throbber.
Another trick you can apply is to use Blocks By Ajax on a timer to reload adverts every XX seconds, thus facilitating swapping ads while a visitor sits on a page. To do that you would obviously need to add some random picking option to your block and then make the random pick from the list of adds in the callback from the view.
Then do a forced full page cache of the page. That will cache all the other blocks and the ajax loader for the advert block, so that when the cached page is loaded, the advert block is loaded afterward through ajax.