Reputation: 691
How can I run js / jQuery when it is first time a user is visiting my site / app.
The ways I can think of are through cookies or local storage, but which is proper?
Upvotes: 0
Views: 1142
Reputation: 4513
I would use Cookies as this is the easiest and most supported way, also if you target older browsers - the local storage might not be consistent.
Thus, for such a simple task - use cookies.
Upvotes: 1
Reputation: 17029
Cookies are the best solution because they are less expensive on the server. Also you don't need to save more data than just the cookie itself, meaning the user has already visited your website. Sessions usually are more complex and used to store more information than a cookie could (or should) hold..
For more information see Cookie VS Session
Upvotes: 0