VueJS: Best way to Cache http response data

孤街浪徒 提交于 2019-12-24 19:27:50

问题


I'm finding a best way to Cache http response data in VueJS, Now I use Vuex Store to my Blog. I want to cache all response data when it requested into server.

Specifically, this is my blog:

When I request data by router to blog detail with 1, 3, 4, I have response data. How can I cache it and then I re-route to 1, 3, 4 in the same session, it not re-fetch data and get data cache to display?

Now I use Vuex and I think it slow if has to store too many data.


回答1:


Service Workers were built for this. They can intercept and cache all requests made on your page. With a little extra work, you can easily add offline capabilities.

You can also use the Cache API with window.caches, mind the browser support though.

Another way is to use LocalStorage/IndexedDB to manually store your responses, but that's more work.



来源:https://stackoverflow.com/questions/53535485/vuejs-best-way-to-cache-http-response-data

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!