En ejemplo sencillo de cookies para editar estilos de la web ['ESP','ENG']
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.
![](https://images.hive.blog/DQmdyFjA9MiZvWMoypNXoWfTxWUn3BysmBvhfGJhXo3W85K/cookie.jpg)
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.
![](https://images.hive.blog/DQmXoupAi7sQeTKTi8Z8ecXS4N7vZoY2RZLa4JDS336EZrg/cookie1.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.
![](https://images.hive.blog/DQmYcpxF65wscSTQPQmSbfCgKh3WHrJugoBBeCwD7fXwgfe/cookie3.jpg)
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.