Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can localstorage data be placed in the HTTP header?

I want to use localStorage on the client side and right now I am sending that data in the body of an AJAX request. However, it would be nice to be able to send the data with the page request. Is there a way to place localStorage data (or I guess any data) in the HTTP header such that I can read it with Javascript and store it in localstorage?

like image 625
Justin Cloud Avatar asked Sep 26 '14 17:09

Justin Cloud


1 Answers

There is no automatic way to put something in local storage by passing an HTTP header.

Your idea of reading the header with JavaScript won't work either, assuming you're referring to the page that the JavaScript is running on. The JavaScript has no way to get the response headers directly.

You could always load your data via AJAX or similar.

like image 198
Brad Avatar answered Oct 13 '22 00:10

Brad