LoginSignup
6
3

More than 3 years have passed since last update.

axiosでのJSONファイル読み込み時にキャッシュを無視する

Last updated at Posted at 2019-08-01

当方JavaScript初心者です。頑張ります。

やりたいこと

AWS Lambdaにより定期的に更新されるJSONファイルをwebサイト側にも反映させたい。

生じていた問題

キャッシュのせいでファイルが更新されたことになっていなかった。

対処

GETリクエストの際に渡すパラメータにタイムスタンプを手動で付与する。
下記コード内での?timestamp=${new Date().getTime()}の部分です。

  setInterval(function update_members(members){
    axios.get('URL?timestamp=${new Date().getTime()}',headers)
        .then(response => {
          res = response.data;
          console.log(res);
          });
        }).catch( error => { console.log(error); });
  },10000);

参考

6
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3