Take the 2-minute tour ×

I believe I'm not the first person who asks this, but I don't found an answer by googling.
Is it possible to set cookies for JS request?

What I mean:
Let's say I have site www.a.com, the page on that site has JS include www.b.com/data.js. Is it possible to set cookie for JS file? I don't want to read that cookie on client...what I want is that next time that this user will request this or other JS on www.b.com, i will able to get that cookie on server.

share|improve this question
+1 because i don't see why you were given a -1 without a comment being left –  Brad Dec 31 '12 at 10:33
add comment

1 Answer

up vote 0 down vote accepted

Yes this should be possible if you put your JS files in a sub-directory. You can then create a cookie just for that directory to keep it visible/scoped just for your needs in data.js.

This post may help give you some background on how cookies are scoped

I have made some assumptions in this answer like you are generating your data.js using some form of server side code (e.g. php, java, etc) so that you can read the client-side cookie on the server.

Feel free to comment if you think I have not understood your question correctly.

share|improve this answer
add comment

Your Answer


