最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to stop pace js plugin to run on page load. I want to fix only on Ajax request - Stack Overflow

programmeradmin9浏览0评论

I'm using jquery pace plugin with progress bar theme, all is working good. but i want to fix this run only on ajax request. After lots of searching i'm deciding to post there. Hope someone having the solution. Currently its running on both Ajax and page load.

Here's the js file call with options given by plugin. but no luck.

<script data-pace-options='{ "document": false }' src="js/pace/pace.min.js"></script>

I'm using jquery pace plugin with progress bar theme, all is working good. but i want to fix this run only on ajax request. After lots of searching i'm deciding to post there. Hope someone having the solution. Currently its running on both Ajax and page load.

Here's the js file call with options given by plugin. but no luck.

<script data-pace-options='{ "document": false }' src="js/pace/pace.min.js"></script>
Share Improve this question edited Nov 29, 2016 at 3:08 Arslan Ali 17.8k9 gold badges63 silver badges83 bronze badges asked Sep 26, 2014 at 10:04 CodeBrieflyCodeBriefly 1,0206 gold badges17 silver badges29 bronze badges 1
  • have you tried loading the pace script on ajax instead of hardcoding it into the page? you can attach the script dynamically and remove it from the header... – Banana Commented Sep 26, 2014 at 10:07
Add a ment  | 

2 Answers 2

Reset to default 15

I found the answer to stop pace.js on page load and here I'm posting this for other users.

Here's the code of js calling.

<script data-pace-options='{ "elements": { "selectors": [".selector"] }, "startOnPageLoad": false }' src="js/pace/pace.min.js"></script>

In this i'm setting pace to given selector and another option startOnPageLoad set to false to avoid loading pace on every page load.

And here is the another question on pace.js which provide me a help.

Using pace.js on loading appended images

If you do not want a script to run on page load, i can think of 2 options at the moment:

1) open pace.min.js file and find the code that makes it run at start, and simply alter it into a function that you can call on your ajax call.

2) remove the pace.min.js link from header, and only attach it on your ajax request/response.

  • Here you can find an explanation on how to attach external code using javascript, for you it will be something like this:

    var fileref=document.createElement('script');
    fileref.setAttribute("data-pace-options","{ 'document': false }");
    fileref.setAttribute("src", "js/pace/pace.min.js");
    document.getElementsByTagName("head")[0].appendChild(fileref);
    
发布评论

评论列表(0)

  1. 暂无评论