+
95
-

小程序如何对图片进行缓存减少对cdn的请求产生的流量费用?

小程序如何对图片进行缓存减少对cdn的请求产生的流量费用?

网友回复

+
15
-

写一个下载到localStorage的辅助函数

const fileSystem = wx.getFileSystemManager()

const getStorageImage = (web_image) => {
  let webImages = wx.getStorageSync('webImages') || []
  let webImage = webImages.find(y => y.web_path === web_image)
  if (webImage) {
    try {
      fileSystem.accessSync(webImage.local_path)
      return webImage.local_path
    } catch(e) { 
      let webImageIdx = webImages.findIndex(y => y.web_path === web...

点击查看剩余70%

我知道答案,我要回答