4

I'm making a website (don't open in IE) where I use Ajax to load a view. I now want to use BOOST to cache the view as HTML.

These pages should be "BOOSTED":

http://www.spanjevakantiewinkel.nl/regio/ajax/8 http://www.spanjevakantiewinkel.nl/regio/ajax/9 ...

Should I use JSON instead of my way to load the view? Any idea how?

The ID (8,9,...) is given by hovering a small image beneath the large header image. Then the view will be loaded, but always within the database, I want HTML pages made with BOOST.

function dynamic_regio_menu() {
  $items = array();

  $items['regio/ajax'] = array(
    'title' => 'Dynamic Regio',
    'page callback' => 'dynamic_regio_get_by_category_id',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK
  );    
  return $items;
}

function dynamic_regio_get_by_category_id($cat_id){
    $viewName = 'regio_submenu'; // The name of the view we are going to load

    $args = array($cat_id);  // Array of arguments we set for the view.
    $displayId = 'block'; // The display id of for the view. 

    // Call the views_embed_view function to returned themed view output
    $html = views_embed_view($viewName, $displayId, $args);
    echo $html;
}
xhr = $.ajax({
  type: 'POST',
  url: '/regio/ajax/' + this.parentNode.getAttribute('tid'),
  success: updateData, dataType: 'html',
});
8
  • how do you load the view in your js ?
    – rémy
    Mar 23, 2012 at 9:43
  • 2
    For starters, I would suggest using hoverintent to prevent all the aborted POST requests.
    – Countzero
    Mar 23, 2012 at 9:48
  • Hoverintent sounds like a good idea, but first I want to make it faster... The loading of the view is now in my question. Mar 23, 2012 at 10:37
  • 1
    You've mentioned that you've enabled Boost in the comments, but make sure you've also enabled the caching of ajax requests in Boost too... (would have commented directly but I don't have enough rep sadpanda)
    – George
    Mar 23, 2012 at 12:27
  • 1
    how did you set the caching on the view ? does the content change often ? does it save the cache every time (do you see the update cache for each request) ? Did you try "precaching" for some of the parameters ?
    – mojzis
    May 3, 2012 at 8:43

5 Answers 5

1

I think the problem is how your views are cached - if you say it is sometimes slow, it is most probably because those times the cache is beeing saved. If the content doesnt change often, you might just prolongue the interval. Another option is to use Views content cache. But basically if you have enough visitors (and enough people hovering the images :), they will only wait from time to time ...

4
  • I changed my question. Using BOOST to make HTML pages from the URL's is what I'm looking for. Caching of the view is enabled, but I use ID's of regio's to change the result of the view. Also, I think BOOST is faster then everything else. Should I change the output of my Ajax request to JSON, and not direct HTML like I do now? Any idea how I can see if a page is loaded with BOOST or not? May 9, 2012 at 11:59
  • I use my own module to link the VIEW with a URL. So views caching won't do anything I think? Maybe I should change my view? Is it possible to have let's say 10 pages for 1 view? spanjevakantiewinkel.nl/regio/ajax/8 spanjevakantiewinkel.nl/regio/ajax/9 spanjevakantiewinkel.nl/regio/ajax/10 ... May 9, 2012 at 12:04
  • There was a snippet from the queries run when the view is beeing shown (did you delete it in the meantime ?) And from that it was clear that there was some cache beeing saved (update), i think it was even clear that it was the cache from views. So you should now check the settings of the caching on that view, and think about the data that is beeing shown - how often does it change and so on ... The best is the module i suggested - that will help you to only fill the cache once the data is changed.
    – mojzis
    May 9, 2012 at 20:12
  • boost saves stuff to fysical files, you should be able to see the files and thus determine what is beeing cached by boost. I dont think it is a big difference in this case whether you use json or html, i personally would stick with html.
    – mojzis
    May 9, 2012 at 20:14
1

The Query time is simply the time it took for the DB to send the result of the query to be returned. The page execution takes into account all of the processing of those results.

This is why it's so important to have Caching enabled.

This may explain more of Views caching: Are views cached through the core caching mechanisms or should I be setting the caching directly in each view?

0

I am not sure if it can help or not but when I try to make ajax I have to call drupal_exit() I don't want drupal to get all page element just this string

function dynamic_regio_get_by_category_id($cat_id){
    $viewName = 'regio_submenu'; // The name of the view we are going to load

    $args = array($cat_id);  // Array of arguments we set for the view.
    $displayId = 'block'; // The display id of for the view. 

    // Call the views_embed_view function to returned themed view output
    $html = views_embed_view($viewName, $displayId, $args);
    echo $html;
    drupal_exit();
}
0

I would definitely advise to check if you have removed modules that are still enabled. This is a real performance killer because Drupal is searching for the module files.

The behavior that you describe looks like this issue.

0

OK, I know this is an old thread, however, I just went through quite a bit of trouble with this and thought I should post here so others will know what my problem was.

first and foremost, verify that your view is not trying to render every single node and comment in the content type if there is a lot of content! It will dismally slow the site doen even if you are using caching, etc. The problem only manifested itself after migrating 56000 or so comments onto 30000 nodes.

The pager count evidently counts nodes and comments and my view had a contextual filter for the logged in user that was not working as it should. Once I got it working, the views are fast and everything is good so I hope this helps someone down the road.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.