How to stop js plugin to start page loading. I want to fix only on Ajax request

I am using jQuery pace plugin with progress step theme, everything works well. but I want to fix this run only on ajax request. After many searches, I decide to post there. Hope someone has a solution. It currently works on both Ajax download and page.

Here's a js file call with the parameters specified by the plugin. but no luck.

<script data-pace-options='{ "document": false }' src="js/pace/pace.min.js"></script> 
+7
javascript jquery ajax
source share
2 answers

I found an answer to stop dark.js from loading the page, and here I am posting this to other users.

Here the js code calls.

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

In this, I configure the step to the specified selector, and the other startOnPageLoad parameter is set to false to avoid loading rates at each page load.

And here's another question on how to help.

Using pace.js when uploading added images

+9
source share

If you do not want the script to be executed when the page loads, I can currently present 2 options:

1) open the pace.min.js file and find the code that will run it at startup, and just change it to a function that you can call when ajax is called.

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

  • Here you can find an explanation of 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
source share

All Articles