通过Web应用程序在客户端上存储用户首选项的标准方式 [英] Standard Way of Storing User Preferences on Client via Web Application

查看:91
本文介绍了通过Web应用程序在客户端上存储用户首选项的标准方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到这可能不是最适合的SO,所以请告诉我应该移动/如果是这样的情况下发布。

I realize this might not be a best fit for SO, so please tell me where I should move/post this if that is the case.

我的想法是在用户登录系统后,以Cookie的形式将用户首选项存储在客户端上。如果用户修改所述首选项,请更新Cookie。我需要这样做,因为一些偏好是客户相关的,需要通过JavaScript来查看。

My idea is after a user signs into the system, store the user preferences on the client in the form of cookies. If a user modifies said preferences, update the cookies. I need to do this because some of the preferences are client related and will need to be looked at via JavaScript.

我意识到我需要存储在服务器上的首选项以及。只是想知道是否把它们下降到饼干是一个好主意。我的应用程序主要是ajax驱动,所以我想拉下一次偏好,只是存储他们。我不想为每个服务器请求推送它们。

I realize I'll need the preferences stored on the server as well. Just wanting to know if pulling them down into cookies is a good idea. My app is primarily ajax driven so I'd like to pull the preferences down once and just store them. I don't want to push them with each server request.

我想避免像本地存储这样的东西,这样我就不必担心浏览器许多。

I'd like to avoid things like Local Storage so that I don't have to worry about browsers as much. Cookies seem to be supported heavily by all browsers.

任何人都同意或有更好的方法?

Anyone concur or have a better way?

推荐答案

一般来说,cookies是一个好主意,只要你不必存储大量的数据。使用Cookie存储内容时,请记住以下几点:

Generally cookies are a good idea, provided that you don't have to store a lot of data. Just few things to keep in mind when using cookies to store stuff:


  • 用户可以手动编辑偏好设置,没有额外的服务器端检查

  • user can edit the preferences by hand so make sure you don't have things like is_root=false without additional server side checks.

这可以是烦人的。 is_root = false 当用户删除cookie和偏好设置后,我会去一个服务器端的偏好设置存储映射到cookies,以便JavaScript可以使用它们。

this can be annoying when user removes cookies and preferences are gone, I would go for a server side preferences storage mirrored to cookies so JavaScript can use them.

其他可能性是使用嵌入式偏好设置的动态JavaScript,而不是静态文件 - 您可以提供与提供动态HTML相同的JavaScript,但是您必须小心缓存。

Other possibility would be to serve dynamic JavaScript, with inlined preferences, instead of static files - you could serve JavaScript the same as you serve dynamic HTML, but then you have to be careful with caching.

这篇关于通过Web应用程序在客户端上存储用户首选项的标准方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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