简体   繁体   中英

How can I store resources in a cookie for faster load time

I know how to set a cookie whether it be in javascript or php, but from all the examples on the inte.net I only see something similar to this:

setcookie("name", "Chris", time()*3600, "/")

But there is no documentation or tutorial on how to apply this to a real appliaction and store real data in the cookie (and not just a name like "Chris" for tutorial purposes).

I would like the clients browser to remember session IDs and static resources like images, stylesheets, javascript,... (for faster load time)

Should I just send a json object with the url location of the resources and the session ids as key/value pairs or how is that done?

Thank you for your answers

The static resources can be cached intrinsically by the browser by using the Cache Control Headers .

You don't need cookies to do it. Just make sure you set appropriate Cache Control Headers on your web server, for any static resource you desire.

Also, if you try to store static content (like images etc) in the cookies, you need to write your own code to get it back from the cookies and render into the DOM (which is highly costly).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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