Lets say I have a php page... I want the javascript in that page to access some user information variables (after logged in), such as userid, email, etc. If I use ajax, then it will take an extra half second, because the page has to load, then wait for ajax to go get those variables, so I'd rather embed it in the page, but that seems questionable as far as security to embed an email in the source.
Here are my options can you think of a better way?
1 - Embed the data into the php on the first request
<html>
<script>
user_email='<?php echo $user_email; ?>';
</script>
2 - Have data load separately from a js/php file so its not in original page source
<html>
<script src="userdata.js.php"></script>
--- userdata.js.php ---
user_email='<?php echo $user_email; ?>';
3 - Request data via ajax after page loads (would be slower)
<html>
<script>
$(function(){
$.post('getuserdata.php',[],function(result){
userdata=result;
});
});
</script>