2017-11-01 4 views
0

私はReact Nativeを使用していますが、私が遭遇した問題はサムネイルをダウンロードしています。 実際、私は29889の親指をダウンロードしていますが、それは遅すぎます。ここ は私のコードです:JavaScriptがダウンロード速度を向上させる

recursive_thumb(skip, count) { 
    if (skip < this.state.totalMarkerCount) { 
    let thumbs = [] 
    for (let i = 0; i < count; i += 1) { 
     thumbs.push(this.downloadThumb(this.state.thumbs[skip + i])) 
    } 
    Promise.all(thumbs) 
     .then(data => { 
     this.setState({ 
      totalCount: this.state.totalMarkerCount, 
      fetchedCount: skip + count 
     }) 
     this.recursive_thumb(skip + count, count) 
    }) 
    .catch(reason => { 
     this.recursive_thumb(skip + count, count) 
     this.setState({ 
     totalCount: this.state.totalMarkerCount, 
     fetchedCount: skip + count 
     }) 
    }) 
} else { 
    setThumbDownloaded() 
    this.checkTownDownloaded() 
} 


downloadThumb(element) { 
    console.log(element) 
    return new Promise((resolve, reject) => { 
    RNFetchBlob.config({ 
    // add this option that makes response data to be stored as a file, 
    // this is much more performant. 
    fileCache: true, 
    path: `${DocumentDirectoryPath}/thumbs/${element}` 
    }) 
    .fetch(
     'GET', 
     `https://www.searchforsites.co.uk/app/images/default/${element}`, 
     { 
     // some headers .. 
     } 
    ) 
    .then(res => { 
     resolve(true) 
    }) 
    .catch(err => { 
     // console.log('Error: ', err); 
     // this.setState({ modalOpen: false, regionUpdated: true }); 
     // this.findUser(); 
     reject(true) 
    }) 
}) 
} 

我々はそれが良い経験になるスレッドを使用することができます。 全データのダウンロードには15分かかります。

天才解はありますか?

ご協力いただきありがとうございます。

+0

画像の遅延読み込みはどうですか?アプリケーションのフロントエンドのニーズに応じて、バッチで、または完全にバックグラウンドでロードするように画像を設定することができます。 –

答えて

0

アプリケーションのフロントエンドですべての画像を一度に取得する必要がない場合は、アプリのリワークを行って画像を読み込み、パフォーマンスを向上させてください。

  • This blog post walks through an example.

  • 遅延ロード

  • See the React Lazy Load npm package here

      は間違いなく、パフォーマンス/ロード時間の改善に役立たせていただきます。また

      検討する価値は、ページごとに表示される画像の数を制限するために、アプリケーションやテンプレートの構造を手直しすることができます。たぶん、ページがAjaxを介してバッチでロードされた無限のスクロール動作を持つ可能性があります。

  • +0

    あなたの助言に感謝します。私は一度にすべての画像をダウンロードしなければならない。 –

    0

    解決策1:WHYと、一度に30.000枚の画像が必要な場合を考慮してください。これは悪いデザインの選択のように思えます。

    解決方法2:zipファイルにそれらを入れて、そのファイルを解凍します:溶液2とAny way to unzip file on react-native

    問題は、あなたがRNことを多くの画像を追加しているので、私はそれがうまくいくので、わからないということですレゾルバは知りません。

    関連する問題