Why a single document.write statement is loading both jquery minified and the full jquery files?

StackOverflow https://stackoverflow.com/questions/21117341

Вопрос

I'm experiencing right now an interesting fact:

If I write this to load only jQuery minified version:

document.write('<script type="text/javascript" src="../rtvizion/Scripts/jquery-1.10.2.min.js"></script>');

both versions of jQuery files are being loaded:

jquery-1.10.2.js
jquery-1.10.2.min.js

as can be seen in Google Chrome Sources:

enter image description here

If I comment out that document.write line then no jQuery file gets loaded.

The problem I have with both files loading is that it's creating duplicate objects/handlers in my own code.

Of course I can safely delete the one not minified (jquery-1.10.2.js) since I'm not using/referencing it anywhere but I'm really curious about what's causing this behavior...

Why is this happening?

Это было полезно?

Решение

jQuery uses SourceMaps, this enables you debug minimized code.

When you open the console and the setting General > Source : Enable JS source maps is enabled, then chrome checks for the SourceMap, and out of the sourcemap creates maps to the original version.

This is why you see both version.

You see both files, because a minimized file could contain multiple files, which when source map is enabled will be displayed as individual ones.

EDIT
The files referenced by the source map are not immediately loaded so they don't appear in the network tab. Only if the content is displayed while debugging they will be loaded and only at that time you will see them in the network tab.

Другие советы

Well... after posting the question and following the advice from Salman A. I could see that the problem was not with document.write but with another app that loads dynamic widgets into the page. The widget also has a script tag linking to jQuery. This causes the problem in my case.

Google Chrome's Sources tab is showing both jQuery files but if I look at the page's source in the Elements tab I see only the minified one present. Looks like the Sources view is misleading!

t.niese's answers it all.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top