0

I have an HTML that uses Jquery. Let's say in the I call to them.

<head>
<script type="text/javascript" src="jquery.min.js"></script> 
<script type="text/javascript" src="jquery.jshowoff.min_130315_page.js"></script>
</head>
<body>
    <script>  </script> <!-- jquery.jshowoff plugin will be used below! -->
    <div> </div>
    <div> </div>

    <!-- And an ads extension adds a link to jquery again. -->
    <script type="text/javascript" src="jquery.min.js"></script> 

    <!-- scripts below will jquery.min.js -->


</body>

My question is. What will be the effect of this?

  1. Will calling jquery again disable the plugin (jquery.jshowoff)?
  2. Will the browser only be able to read jquery.min and not the plugin?

I hope this is clear enough if so, I can be extra clear. Thank you.

aps_hole
  • 23
  • 1

2 Answers2

2

As far as I know, the second jQuery script will overwrite the first and there goes the loaded plugins too. How about if you move your plugin script tag below the ads part and erase the first jQuery tag. Then just make sure your code waits for jQuery ready event?

Roope Hakulinen
  • 7,326
  • 4
  • 43
  • 66
1

The effect in some cases depends on the script. In most cases merely importing a library twice won't cause any problem but it is wasteful. In other cases if a script is doing some set up then importing it twice has the following effect, the second instance of the script un-does all the work of the first instance.

In your case I guess you have no control over the 'ad extension' so you might have to control the order of the scripts to prevent conflicts and contradictory results.

As @Sanfor states pulling in these two scripts will cause the second to over-write the other. Don't forget that JS scripts are executed in order.

Have you tried putting your scripts at the bottom or at least below the 'ad extension'?

Daniel Hollinrake
  • 1,768
  • 2
  • 19
  • 39
  • 1
    Last time I looked into it, it was the case that second including of jQuery overwrites the first global variable (window.jQuery and window.$) which causes all the loaded plugins to go undefined? – Roope Hakulinen Oct 16 '14 at 14:00
  • Yes, you are right. It depends on what the script is doing. That's why I'm advising to keep it clean. I'll edit my answer to emphasise this. Thanks. – Daniel Hollinrake Oct 16 '14 at 14:02
  • @sanfor I guess my guess was right. Thanks for clarifying and I don't have control of the ads extension at the moment. Most likely, since the ads will always be at the very bottom, I'm thinking of adding the plugin there as well. – aps_hole Oct 16 '14 at 14:03
  • @DanielHollinrake I indeed am getting contradictory results and the plugin does not end up working. – aps_hole Oct 16 '14 at 14:04
  • Also, take a look into [this](http://stackoverflow.com/a/11948216/1744702) as it seems to be one way to solve it. – Roope Hakulinen Oct 16 '14 at 14:05