Stop Meteor http from slowing down page requests -


i'm quite new meteor , relatively new js well.

the code i'm using is:

server/methods.es6

var cheerio = meteor.npmrequire('cheerio');  /*****************************************************************************/ /* server methods */ /*****************************************************************************/ meteor.methods({   /*    * example:    *    * '/app/items/insert': function (item) {    * }    */   player: function () {     const url = 'http://cdn.content.easports.com/fifa/fltonlineassets/c74ddf38-0b11-49b0-b199-2e2a11d1cc13/2014/fut/items/web/165434.json';      const response = meteor.http.get(url);      return response;   } }); 

client/templates/cars/cars_list.es6

meteor.call('player', function (err, res) {   if (err) console.log(err);    console.log(json.parse(res.content));    session.set('player', json.parse(res.content)); });  /*****************************************************************************/ /* carslist: event handlers */ /*****************************************************************************/ template.carslist.events({ });  /*****************************************************************************/ /* carslist: helpers */ /*****************************************************************************/ template.carslist.helpers({   cars: function () {     return cars.find();   },   player: function () {     return session.get('player');   } }); 

client/templates/cars/cars_list.html

<template name="carslist">   <h1>cars list</h1>    {{ player.item.firstname }}    <table class="table table-hover">     <thead>       <tr>         <th>brand</th>         <th>model</th>         <th>fuel type</th>         <th>body style</th>         <th>top speed</th>         <th>power</th>         <th>edit</th>       </tr>     </thead>      <tbody>       {{# each cars }}         {{> car }}       {{/ each }}     </tbody>   </table> </template> 

most of test code try , http requests.

when remove code related player instant. when player code there page loads instantly cars data doesn't show until http request player resolved. there way put http request in background while else used do?

also there way loop http requests , show data receive back?

i advise put method code in both folder. way, latency compensation won't affected , user interface update fast supposed to.

if need hide of code client, can put in both client , server folders. have not tested this, assume if result of client call different (i.e. messed console) rollback data server one.

this way, simulate method results server while has not come yet. however, keep in mind whatever setup use, end having wait website data go on, whether on client or server. if call data that, think not stop mongo data, js functions execution (the event loop). might wrong (newbie here too)

maybe should read fiber , future, , async calls. seems me way go.

good luck!


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -