3

I am trying to load a JS file using yepnope using the below code:

yepnope({
    load: '<?php echo base_url(); ?>static/js/highlight.min.js',
    complete: function()
    {
        hljs.tabReplace = '    ';
        hljs.initHighlightingOnLoad();
    }
});

However when I look in firebug to see what is loading it shows that it is being loaded twice. Am I doing anything wrong because I am confused?

enter image description here

Malachi
  • 33,142
  • 18
  • 63
  • 96

1 Answers1

6

Should have really looked harder for existing answers before posting.

I'm seeing two requests in my dev tools, why is it loading everything twice?

Depending on your browser and your server this could mean a couple different things. Due to the nature of how yepnope works, there are two requests made for every file. The first request is to load the resource into the cache and the second request is to execute it (but since it's in the cache, it should execute immediately). Seeing two requests is pretty normal as long as the second request is cached. If you notice that the second request isn't cached (and your script load times are doubling), then make sure you are sending the correct cache headers to allow the caching of your scripts. This is vital to yepnope. It will not work without proper caching enabled. We actually test to make sure things aren't loaded twice in our test suite, so if you think we may have a bug in your browser regarding double loading, we encourage you to run the test suite to see if the double loading test passes.

Community
  • 1
  • 1
Malachi
  • 33,142
  • 18
  • 63
  • 96