Firstly, thanks for your work on this - its a real help for a project i'm working on.

While adding the patch to turn off autoloading and also tweaking the module for my requirements, I was surprised to notice that for each time this pager loads the next 'page' of data for the view it makes a full request for the page, including all the theme, blocks etc.

This seems to me a waste of bandwidth and cpu cycles both for the client and server, so I have been looking into ways of making the process more lightweight.

The solution I came up with is to create a menu hook that outputs solely the content of the view and skips generating the rest of the page. To do this I had to add in a special url into the theme and change the behaviour somewhat.

I have created a sandbox clone of this project as currently I am not entirely happy with the system myself, and therefore it needs some more work before I can even suggest a patch. However, if this is a direction you want to go in anyway, seeing this implementation may give you some additional pointers.

The sandbox project is located here:
http://drupal.org/sandbox/smoothify/1121362

The primary commit for this functionality is here:
http://drupalcode.org/sandbox/smoothify/1121362.git/commitdiff/d1265af

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rjbrown99’s picture

Status: Active » Needs work

+1 from me, great approach and more efficient. Since there is a sandbox I'll change this to "needs work".

I'd also suggest you add some check_plain() functions in views_infinite_scroll_ajax(). Not a good idea to blindly accept unvalidated input from the client.

jrb’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Issue summary: View changes
FileSize
4.05 KB

This is a great idea, but the old sandbox seems to be missing.

@rjbrown99

I see that you're using something like this on the "Go Chic or Go Home" site listed on the project page under "Views Infinite Scroll powered pages". Based on looking at the source of that site, I've taken a stab at a patch for the 7.x version to make this work. You might consider posting what you're using there (I didn't see anything like it in the issue queue).

My patch does work for me, but it doesn't respect the access settings used by the View, so it's not quite ready for prime time. It is a start, though.

Sam152’s picture

I have been working on something similar. I have already pushed a working version of this code to the 8.x branch and this patch is the backport to D7 which I have been using in production for a few months. It only renders the view, like your approach but it also removes the external dependency on the jQuery library.

It's quite simple, it tells views to use AJAX and then simply hijacks the 'replace' command and tells it to 'inset below' instead. The only thing stopping me from pushing this out as an approach for 7.x-2.x is it doesn't currently support automatically paging to the next page.

The 8.x version does and the JavaScript is practically identical if anyone wanted to backport it.

jrb’s picture

Status: Needs work » Needs review
FileSize
21.77 KB

I took the JavaScript from the 8.x version and made it work here (with your patch). I also have it using the "Loading..." gif.

Full patch attached.

Sam152’s picture

Cool, I will definitely have a review and see if we can get 7.x-2.x cranking. Any chance you can post an interdiff?

jrb’s picture

Interdiff attached.

Sam152’s picture

Status: Needs review » Needs work

Review attached.

  1. +++ b/views-infinite-scroll.js
    @@ -13,4 +18,31 @@
    +      var settings = settings.views_infinite_scroll[0];
    

    Will this break with multiple views on the same page?

  2. +++ b/views-infinite-scroll.js
    @@ -13,4 +18,31 @@
    +      var loadingImg = '<div id="views_infinite_scroll-ajax-loader"><img src="' + settings.img_path + '" alt="loading..."/></div>';
    

    Using an ID here breaks multiple views on the same page.

  3. +++ b/views-infinite-scroll.js
    @@ -13,4 +18,31 @@
    +      $('.pager--infinite-scroll', context).once().each(function() {
    

    Has this been tested? .once().each is a newer version of jQuery?

  4. +++ b/views-infinite-scroll.js
    @@ -13,4 +18,31 @@
    +        $window.on('scroll.views_infinite_scroll', function() {
    

    This behavior is configurable in the plugin settings, but isn't checked in here?

  5. +++ b/views-infinite-scroll.js
    @@ -13,4 +18,31 @@
    +            $window.off('scroll.views_infinite_scroll');
    

    I don't think this is correct for jQuery 1.4.4.

  6. +++ b/views_plugin_pager_infinite_scroll.inc
    @@ -75,8 +75,18 @@ class views_plugin_pager_infinite_scroll extends views_plugin_pager_full {
    +    $img_path = $base_url . '/' . drupal_get_path('module', 'views_infinite_scroll') . '/images/ajax-loader.gif';
    

    Why not just url(...)?

jrb’s picture

@Sam152 - You're right about most of the issues above. I just basically took the JavaScript from the D8 version and made it work with your D7 patch. I happened to be using jQuery Update, so I didn't notice the version-specific issues there. When I get some time, I can try to address them.

For the moment, the patch in #3/#4 has been working for me, but I've been getting some PHP notices. I've attached a new patch that just fixes these notices. The only difference from the patch in #4 is this:

diff --git a/views_infinite_scroll.module b/views_infinite_scroll.module
index f868417..f349f53 100644
--- a/views_infinite_scroll.module
+++ b/views_infinite_scroll.module
@@ -51,7 +51,7 @@ function views_infinite_scroll_views_ajax_data_alter(&$commands, view $view) {
     return;
   }
   foreach ($commands as $delta => &$command) {
-    if ($command['method'] === 'replaceWith') {
+    if (!empty($command['method']) && $command['method'] === 'replaceWith') {
       // Change the standard replace command to a custom one which will provide
       // the infinite scroll effect.
       $command['method'] = 'infiniteScrollInsertView';
Sam152’s picture

Good point re: the the above patch. It was fixed in 8.x and probably would have been back-ported if we had a 7.x version.

Let me know when you start working on this. I might also have some time to look at it, so we shouldn't duplicate efforts.

jrb’s picture

Status: Needs work » Needs review
FileSize
22.03 KB

Well, since I was here...

I've attached a new patch that addresses the issues mentioned in #7 above.

Comments / notes:
1. It now works with the default core jQuery.
2. It allows multiple Infinite Scroll views on the same page.
3. It now looks at the "Load subsequent pages manually instead of automatically" setting for the display's pager.
4. RE: Item 3 in comment #7 above, .once().each() is valid.

  • Sam152 committed 13e0fc7 on 7.x-2.x authored by jrb
    Issue #1121530 by jrb, Sam152: Make the ajax loading more lightweight...
Sam152’s picture

Status: Needs review » Fixed

I have pushed a 2.x branch. Going to do some thorough testing and file any follow ups required in the queue. Thanks for working on this.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.