0

At the beginning of the file I have the following code:

$.get(
    "/users/getInfo",
    "json"
).done(function(data){
    window.User = data
})


import './components/map'
import './components/search'
import './components/jobs'
import './components/pagination'
import './components/pages'
import './components/users'

I will need window.User data in the code later on. Is it possible to force everything else to wait for the get request to be done?

I am trying this approach because I don't wanna expose user data directly with a code similar to this one:

 <script>var User = <?php echo $user; ?>;</script>

The code from above will be minified so the user data will be a bit harder to find if anyone tries to find it.

5
  • can't you use async: false ?
    – Tim567
    Commented Jun 11, 2020 at 8:34
  • @freedomn-m I am using php for back-end, but I need user data in the javascript also, but I want to remove the call to the server each time I need it.
    – Sasha
    Commented Jun 11, 2020 at 8:40
  • 1
    @freedomn-m Oh! Didn't know that. I also don't use it but just know it exists.
    – Tim567
    Commented Jun 11, 2020 at 8:42
  • @freedomn-m I doing that already, but I am trying not to expose the user data directly (the JS will be minified, so this data would be a bit harder to find).
    – Sasha
    Commented Jun 11, 2020 at 8:48
  • Sorry about that, I thought it wasn't important to the question.
    – Sasha
    Commented Jun 11, 2020 at 8:52

0

Browse other questions tagged or ask your own question.