简体   繁体   English

构建客户端应用程序时,在本地存储中的密钥中使用前缀有什么好处? (尤其是在angularjs / angular应用中)

[英]What are the benefits of using prefix in keys in local storage when building client app? (especially in angularjs / angular apps)

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. 提供易于使用的本地存储服务的各种库(例如https://www.npmjs.com/package/angular-2-local-storagehttps://www.npmjs.com/package/angular-local- storage )可以为该服务密钥在本地存储中创建的所有前缀设置一个通用前缀。

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). 由于使用了每个域分别保存的本地存储,因此,使用子域(例如test.youdomain.com或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. 但是,当您有很多键时,最好给它们加上前缀。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM