0

Currently I place a large array in a cached file, that gets loaded into an iframe. The data gets loaded into a javascript variable.

Now I have the variable containing the data and do not need the javascript that was used to load it (the script tag in the iframe) I find that I cannot get rid of this script tag (really the DOM 'copy' of it). I thought deleting the iframe would do it, but does not.

Is there a way to do this?

If I use ajax to download the data, I do not have this extra bulk, but then it takes time to download each time.

OR

Is there a better way to do this?

4

2 回答 2

1

The iframe technique is bulky and is unnecessary, unless you are using it go around the same-origin policy. To add to that, scripts that are loaded and executed are already in memory. There is no way to pluck them out when they are loaded, even when the DOM elements that loaded them are removed.

Assuming that your data comes from the same domain, one way you can do this is to load them via "AJAX" by using XHR. This loads the contents of that file into a string that can be used by your program. You can store them in JS objects.

So that it will persist, you can use localStorage to persist that data on the client-side. But do note that localStorage has size limits of 5-10MB depending on the browser.

I suggest you use a library that already handles these things. AJAX (with caching) can be done via jQuery and cross-platform localStorage can be done using Persist

于 2013-01-11T04:11:20.853 回答
0

In most cases, using XML to parse, search and read information could come in handy. Why not try that? It goes well with javascript.

http://www.w3schools.com/xml/

于 2013-01-11T04:03:50.567 回答