构建客户端应用程序时,在本地存储中的密钥中使用前缀有什么好处?(尤其是在angularjs/angular应用程序中) [英] What are the benefits of using prefix in keys in local storage when building client app? (especially in angularjs / angular apps)

查看:88
本文介绍了构建客户端应用程序时,在本地存储中的密钥中使用前缀有什么好处?(尤其是在angularjs/angular应用程序中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

提供易于使用的本地存储服务的各种库(例如 https://www.npmjs.com/package/angular-2-local-storage

Various libraries that provide an easy to use local-storage services (like https://www.npmjs.com/package/angular-2-local-storage or https://www.npmjs.com/package/angular-local-storage) give the possibility to set one common prefix for all created by that service keys in local-storage.

由于使用了每个域分别保存的本地存储,因此,使用子域(例如test.youdomain.com或dev.yourdomain.com)后,密钥应该不会出现冲突"的威胁.

As the local storage is used preserved separately for each domain, it feels like there should be no threat that the keys will get 'conflicted' once using sub-domains (like test.youdomain.com or dev.yourdomain.com).

因此,问题是-为什么在何时以及何时在本地存储密钥中使用前缀?

Therefore the question is - why and when shall we use a prefix in local-storage keys?

(我认为当应用程序中的第三方库使用本地存储时,它可能会防止密钥冲突,但除了我什么也没想到)

(I'm thinking that it might prevent for having conflicted keys when third party libraries in app use local-storage, but except that i can't think of anything else)

推荐答案

为本地存储密钥添加前缀有助于识别密钥是属于您的应用还是属于第三方库.

Prefixing local storage keys helps identify whether keys belong to your app or to 3rd party libraries.

不是必需的.但是,当您有很多键时,最好给它们加上前缀.

It is not required. But when you have a lot of keys it is better to prefix them.

这篇关于构建客户端应用程序时,在本地存储中的密钥中使用前缀有什么好处?(尤其是在angularjs/angular应用程序中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆