I was just experimenting with some javascript, browsing the web for fast search on the client side. I came accross this link where blogger briefly mentions loading data as an executable script by wrapping it in a callback function.
Even though this might not be the best way to do it, can someone explain how this might actually work?
I have been trying the following code in the head section.
<script id="jsonD" type="application/json" src="/data/catalogEntries.json"></script>
I can see in the dev tools that the file is being transferred. But I can't figure out how to use the data in another script.
I also tried the following at the end of the body section.
$(document).ready(function () {
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'application/json';
script.src = '/data/catalogEntries.json';
head.appendChild(script);
})
I am also trying to find out how I can measure the time it takes for the browser to parse the data and compare it with a plain use of eval(). The data that I have is more than 4k Kilobytes.
I know I can do this using XMLHttpRequests and I have done this multiple times but this seemed like a much faster way of parsing a large amount of data based on the blog link that I posted earlier.
Any help appreciated.
Thanks, Paras
UPDATE
Here is a plunker