Use Javascript (no ajax) for Views sorting - Have random sorting on cached pages

Events happening in the community are now at Drupal community events on www.drupal.org.
Posted by mikeytown2 on January 18, 2011 at 8:30pm

We have some hacked up tpl files to accomplish this goal, but I'm looking to create a module where one can select "Global: Javascript Random" as an option. We want to use this elsewhere so a views plugin sounds like the right thing to do.

Why? Lets say this view is used to rotate an ad on your site. If that is cached then the same ad shows until the cache is cleared. AJAX loading does work but for something as simple as this, it puts extra load on the server & slows down rendering time.

How? Lets say for the view it will display 3 nodes; with this plugin it will load 20 nodes (number configurable) and then client side it will use Javascript's Math.random() to select what 3 nodes to display. Inside a noscript tag it will have 3 random nodes, but these will not change until the page is created again.

Has anyone already created a module for this?

Comments

One drawback to be aware of

Posted by dalin on January 18, 2011 at 11:55pm

One drawback to be aware of is that it will require sending a lot of extra HTML to the browser. This may slow down all of your JavaScript, especially in <= IE7 as it means a lot more content to sort through to find the right selector.

--


Dave Hansen-Lange
Director of Technical Strategy, Advomatic.com
Pronouns: he/him/his

New Module

Posted by mikeytown2 on January 20, 2011 at 2:18am

Views Javascript Random

Posted by cbutts on May 26, 2012 at 4:38am

I was looking for a way to randomly display a Featured Attraction based on the rating we gave it. I came across Views Javascript Random and installed it. It works like a charm. Thanks for creating such a cool module.

Views Developers

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

AltStyle によって変換されたページ (->オリジナル) /