How do I prefetch url's in ionic/angularjs?

前端 未结 4 1668
渐次进展
渐次进展 2021-02-19 12:11

I am pretty new to ionic 1 and I am working on an application (with Ionic 1 and angular js) with multiple URLs where each URL brings up a list of categories, followed by a list

4条回答
  •  清酒与你
    2021-02-19 12:46

    Update - As the OP is already aware of and using localStorage, thus additional suggestions :-

    In that case, you could either call all of your service methods for fetching data at startup or you could use a headless browser such as 'PhantomJS' to visit these URLs at startup and fetch the data.

    Thus, your code would look something like :-

    var webPage = require('webpage');
    
    var page = webPage.create();
    
    page.open('http://www.google.com/', function(status) {
      console.log('Status: ' + status);
      // Do other things here...
    });
    

    For more information, regarding PhantomJS, please refer to the following links :-

    http://phantomjs.org/ http://phantomjs.org/api/webpage/method/open.html

    Earlier Suggestions

    Make an HTTP request in your service to fetch the data and store it to localStorage, as is shown below :-

    $http.get('url', function(response) {
    var obj = response.data;
    window.localStorage.setItem('key', JSON.stringify(obj)); // Store data to localStorage for later use
    });
    

    For fetching data :-

    var cachedData = JSON.parse(window.localStorage.getItem('key')); // Load cached data stored earlier
    

    Please refer to the following link for detailed information regarding 'localStorage' :- https://www.w3schools.com/html/html5_webstorage.asp

    Hope this helps!

提交回复
热议问题