0

I'm using horizontal parallax jQuery plugin and have a page--front.tpl.php file. That's my structure:

MENU:

<li><a id="mymenu" href="#/menucontent">news</a></li>

When I click this menu item, go to DIV:

<div id='menucontent' class="fancyscroll-section" style="left:1600px">

    <?php
    $view_mode = 'full'; // Or 'full' for example
    $node = node_load(52);
    $view = node_view($node, $view_mode);
    print render($view);
    ?>

    </div>

But I have a big problem. When i click my site adress, loading all content and items in one time. So, my site is slowly. I thinking use node_load function via Ajax. Searched site and drupal.org but not found a good info.

Is it possible? What can I do for my site speed? Ajax is a good solution?

2 Answers 2

1

Ajax could actually complicate your situation further, since you'd be asking your site to bootstrap once again asynchronously in order to serve the node. Not to say it isn't an option, you can write your own method to retrieve only the information you need via ajax.

I would personally look into caching methods. If your site gets anonymous traffic, try boost. Easily the best improvement for Drupal performance (in my opinion) is APC cache. Hopefully you have root access and can install the APC extension for PHP and then the APC module, the site starts flying after that, for both auth and anon traffic. I'm afraid you might already know this so I'll stop there.

If you still wanna do AJAX stuff, you could install views datasource to output JSON, and add a jquery call the page with $.get and push the content into the DOM. Using views gives you some native caching options as well.

Hope it helps.

1

Yes, you can use ajax for this.

1 Create menu item via hook_menu() with callback


function mysite_menu() {
      $items['ajax/load_node/%'] = array(
        'page callback' => 'mysite_load_node',
        'page arguments' => array(2),
      );
      return $items
    }

function mysite_load_node($nid) { $view_mode = 'full'; $node = node_load($nid); $view = node_view($node, $view_mode); return drupal_json_encode(render($view));
}

2 Write ajax function for loading content and add to your links nid attribute, for example

.... id="mymenu" nid="52" href="#/menucontent">

$('a').live('click', function(){
    var nid = $(this).attr('nid');
    $.ajax({
      url: "/ajax/load_node/" + nid,
    }).done(function(result) {
       // you can load result for needed dom element
    });
  });

Your Answer

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

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