0

I use http://github.hubspot.com/pace/ on a current project which preloads the entire page.

Is it possible to exclude certain elements from preloading?

E.g. I want my #header and #banner element to be visible right away, and let pace do its job for the rest of the page.

For me the "start" event is not triggered?

Pace.on("start", function() {
        alert('heee');
    });

Wheter in the document-ready nor out of the function. Pace.on("done", … triggers just fine.

Update: my major problem at the moment is this …

$(window).load(function(){
    $('body').addClass("page");

    Pace.on('start', function() { 
        alert('start') // not fired
    });

    Pace.on('done', function() {
        alert('done') // fired!
    });
});
JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
matt
  • 42,713
  • 103
  • 264
  • 397

1 Answers1

1

According with the documentation:

"Collectors are the bits of code which gather progress information. Pace includes four default collectors:

Ajax

Monitors all ajax requests on the page

Elements

Checks for the existance of specific elements on the page

Document

Checks the document readyState

Event Lag

Checks for event loop lag signaling that javascript is being executed

They can each be configured or disabled through configuration options of the same name."

paceOptions = {
  ajax: false, // disabled
  document: false, // disabled
  eventLag: false, // disabled
  elements: {
    selectors: ['.my-page']
  }
};

Perhaps

elements: {
   selectors: ['.my-page']
}

Could do the trick.

More here:

"Elements

Elements being rendered to the screen is one way for us to decide that the page has been rendered. If you would like to use that source of information (not required at all), specify one or more selectors. You can comma seperate the selectors to propertly handle error states, where the progress bar should disappear, but the element we are looking for may never appear:"

paceOptions = {
  elements: {
    selectors: ['.timeline,.timeline-error', '.user-profile,.profile-error']
  }
}

It seems a good plugin!


EDIT

To attach code on start it seems that should be:

"If you're using AMD or Browserify, you can pass your options to start:"

define(['pace'], function(pace){
  pace.start({
    document: false
  });
});
Verhaeren
  • 1,661
  • 9
  • 10
  • thanks, I updated my question. I can't seem to find out why my "start" event is not fired. Any ideas? – matt Dec 15 '14 at 18:41
  • I'll take a look, but it seems to me that if your question now is different that your previous question it should be a new question because you got an answer already. Then my answer could get downvoted as *off-topic*. – Verhaeren Dec 15 '14 at 18:49
  • Thank's but I don't know what this means exactly. If I use this snippet in my javascript file I get an error. ` Uncaught ReferenceError: define is not defined`. How do I use this code? what is AMD? – matt Dec 15 '14 at 19:05
  • where do I put this? Does not work for me? The documentation says that there are events like "done" and "start". Why is "done" triggered, but "start" isn`t? – matt Dec 15 '14 at 19:14
  • `pace.start({ alert("");` is throwing an error. Undefined function pace, or punctuation error. – matt Dec 15 '14 at 19:17
  • Doesn't matter where I put it. Either in load, or ready or out of all functions. It's always "undefined". – matt Dec 15 '14 at 19:46
  • Check here, specially from line 177: https://github.com/HubSpot/pace/blob/master/pace.coffee – Verhaeren Dec 15 '14 at 19:47
  • I'm sorry I'm not that into javascript to understand this. – matt Dec 15 '14 at 19:55
  • This might not be relevant to the real problems but pace.start is undefined because of capitalization error it should be Pace.start – Diin Sep 09 '15 at 21:39