En ejemplo sencillo de cookies para editar estilos de la web ['ESP','ENG']

avatar

Hoy me gustaría comentar sobre cómo utilizar las cookies una herramienta bastante conocida por los desarrolladores pero poco utilizada por los que recién empiezan en el mundo de la programación web las cookies se pueden utilizar para muchísimas cosas por lo general se utilizan para autentificación y sesión de usuarios.
Por otra parte también se pueden utilizar para personalizar contenidos, carritos de compras, análisis y seguimiento, para ver preferencias de los usuarios y seguridad.

Today I would like to comment on how to use cookies, a tool well known by developers but little used by those who are just starting out in the world of web programming. Cookies can be used for many things, they are generally used for user authentication and sessions. . On the other hand, they can also be used to personalize content, shopping carts, analysis and monitoring, to see user preferences and security.
En este caso mostraré un ejemplo muy sencillo de una aplicación de cookies es algo muy similar utilizar session storage y local storage. La diferencia es que la cantidad de datos que pueden ser almacenados es mucho menor en las cookies por lo tanto su uso siempre es específico y optimizado además las cookies a la hora de almacenarse se almacenan como si fuera una variable con un valor lo que hace complicado su manejo si no es a través de expresiones regulares u iteradores.
In this case I will show a very simple example of a cookie application, it is something very similar to use session storage and local storage. The difference is that the amount of data that can be stored is much less in cookies, therefore their use is always specific and optimized. Furthermore, when stored, cookies are stored as if it were a variable with a value, which makes it complicated. its handling if not through regular expressions or iterators.

cookie2.jpg

Para este ejemplo que se va a ver ahora lo único que hago es tener una función que cree una cookie con un nombre un tiempo de expiración y un valor que se le pasa por parámetro a la función las otras funciones lo único que hacen es obtener el valor de dicha cookie y por otra parte aplicar un tema al navegador a modo de estilos en líneas en caso de existir la cookie con dicho valor y si no dejar uno por defecto.

For this example that is going to be seen now, the only thing I do is have a function that creates a cookie with a name, an expiration time and a value that is passed as a parameter to the function. The other functions only do is obtain the value of said cookie and on the other hand apply a theme to the browser as styles in lines if the cookie exists with said value and if not leave one by default.

cookie4.jpg



0
0
0.000
1 comments
avatar

Thanks for your contribution to the STEMsocial community. Feel free to join us on discord to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).

You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support. 
 

0
0
0.000