Note that there are some explanatory texts on larger screens.

plurals
  1. POchrome extensions: Which will be better, ajax or chrome.extension.sendRequest?
    primarykey
    data
    text
    <p>Not just faster but better both in speed and using resources/memory.</p> <p>I have an app where I put in suggestions as user types in an input-type-text. So, should I use ajax to communicate between two pages or chrome.extension.sendRequest?</p> <p><strong>EDIT</strong></p> <p>I have a packaged app, all the app info is stored in background.html's websql database. there is an input-type-text on index.html (which opens when someone clicks on app logo form new-tab page)</p> <p>The input on the index.html fetches suggestions from the database of background.html as the user types in it. (just like google does when you start typing the query on google homepage) I can fetch suggestion data in two ways, using XmlHttpRequest and through chrome's message passing api. Since there will be a lot of requests to the background.html, i was wondering which method would be efficient..</p> <p>The app in question: <a href="https://chrome.google.com/webstore/detail/fddboknafkepdchidokknkeidnaejnkh?hl=en-US" rel="nofollow">https://chrome.google.com/webstore/detail/fddboknafkepdchidokknkeidnaejnkh?hl=en-US</a></p> <p><strong>EDIT 2</strong></p> <p>The app is 100% offline. I am not connecting to any server or website. I am not loading any external script, not even jquery. All the app ever connects to is the files in it's own directory. background.html loads when pc starts and index.html loads when user clicks the app icon in new tab page. To see everything in action, you can install the app and see it for yourself.</p> <p><strong>EDIT 3</strong></p> <p>I am using the regular ajax to call index.html from background.html and it seems to work fine. By the way, both index.html and background.html are in 'html' directory.</p> <pre><code>function ajaxcall(url,callback) { var call = new XMLHttpRequest(); call.onreadystatechange=function() {if(call.readyState==4) callback(call.responseText);} call.open("GET",url+'#'+Math.random(),true); call.send(null); } ajaxcall('/html/index.html', function(response) {console.log('foo')}); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COCan you show what you add in index.html to handle this XHR request? Anyway, I don't think it is a good idea to use this technique. I think `getBackgroundPage` imposes no extra penalty in terms of speed and resources, You don't create extra objects with it. You don't access the network. You only use objects that are already in the memory. You should definitely try that out.
      singulars
    2. COnothing.. no code in index.html. i use hash (#) to send url variables and read them with js on index.html. and thanks for the idea, i have heard about getBackgroundPage and i have this last concern. Both the index.html and background.html (along with their own js files) are quiet heavy. will i be calling off the code that i dont need..? or what if the index.html is not open but background.html is? with chrome's message api its request just gets ignored. Thanks alot for you time, i hope i make sense.. :)
      singulars
    3. COYour backgroundpage will always be in memory so I don't think it will be extra load when you reference it in index.html. If index.html is not open then it can't call any code. If I share code between pages I sometimes do like the following example: ´var jQuery = backgroundPage.jQuery;´. But I'm not quiet sure whether this is good practice. I haven't had any issues with it though.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload