/    Sign up×
Community /Pin to ProfileBookmark

Loading slideshow using Ajax

I am experimenting with Ajax in an attmept to improve page loading times.
I have a slideshow with 7 slides, each image is 1200px x 400px and roughly 200-250KB in size

My plan: load the first image on Page Load and then load the other 6 slides after the DOM is loaded using Ajax.

I got it working ok using the following:

“`
jQuery( document ).ready( function( $ ) {
// make sure rslides exists on page
if ( $( “.rslides” ).length )
{
setTimeout(function(){ loadSlides($); }, 1000 );
}
}

function loadSlides($)
{
// Add nonce to formdata
formdata = new Array();
formdata.push({name: ‘action’, value: ‘omg_load_slides’ });
formdata.push({name: ‘nonce’, value: ajax_object.ajax_nonce });

jQuery.ajax({
type: “POST”,
url: ajax_object.ajaxurl,
data: formdata,
success: function(response) {
//Call callback function
loadSlidesCallback(response);
},
error: function(response) {
//Call callback function
loadSlidesCallback({“success”:0,”message”:”Unexpected error occurred”});
},
complete: function (data) {
// Initiate home banner slider
$(“.rslides”).responsiveSlides({
auto: true, // Boolean: Animate automatically, true or false
speed: 1000, // Integer: Speed of the transition, in milliseconds
timeout: 4000, // Integer: Time between slide transitions, in milliseconds
pager: false, // Boolean: Show pager, true or false
nav: true, // Boolean: Show navigation, true or false
random: false, // Boolean: Randomize the order of the slides, true or false
pause: false, // Boolean: Pause on hover, true or false
pauseControls: true, // Boolean: Pause when hovering controls, true or false
prevText: “”, // String: Text for the “previous” button
nextText: “”, // String: Text for the “next” button
maxwidth: “”, // Integer: Max-width of the slideshow, in pixels
navContainer: “”, // Selector: Where controls should be appended to, default is after the ‘ul’
manualControls: “”, // Selector: Declare custom pager navigation
namespace: “rslides”, // String: Change the default namespace used
before: function(){}, // Function: Before slide loads callback
after: function(){} // Function: After slide loads callback
});
}
});
}

function loadSlidesCallback(data)
{
var jdata = JSON.parse(data);
if(jdata.success)
{
jQuery(‘ul.rslides’).append(jdata.html);
}
}
“`

BUT … When I do a speed test using GTMetrix or Pingdom, these images are still loaded in the Waterfall Chart
and still contribute to the Page Size and load speed… Is it possible call this function in alternative way so that it is not counted towards the page load or is this expected behaviour and can’t be avoided?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@SempervivumOct 23.2020 — My guess:

The tools you mentioned consider all images as a part of the page and therefore include it in the page size and the loading time.

They do not take into account the user's experience: The page is already completely visible after the first image has been loaded.
×

Success!

Help @php-bgrader spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...