Oden
Oden

Reputation: 628

External JS loads multiple times

When JavaScript on my page is loaded from a CDN (or any external source) it loads multiple (5+) times. JS files that are local only load once.

Here is the relevant HTML:

<html>
  [...]

  <body>
    [...]

    <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/jquery-migrate/1.2.1/jquery-migrate.min.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.3.1/jquery.cookie.min.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
    <script src="js/index.min.js"></script>
    <script src="js/bootstrap-notify.min.js"></script>
  </body>
</html>

Here is a screenshot of the requests from Chrome's Resources tab:

Chrome Resources

As you can see, bootstrap.min.js (external) loads multiple times - but bootstrap-notify.min.js (local) loads once.

This happens with any external source, not only cdnjs.cloudflare.com.

EDIT: Fixed it. It was a problem related to the AJAX requests in my JavaScript.

Upvotes: 0

Views: 918

Answers (1)

Blender
Blender

Reputation: 298196

$.fn.getPage is your problem. You insert the entire HTML document into your current document, which will also insert the <script> tags.

Only replace the body:

$(data).find('body').children().appendTo(self.find('body').empty());

Upvotes: 1

Related Questions