开发者

How can I send a background 'warmup' request to GAE from a static HTML page?

开发者 https://www.devze.com 2023-03-21 14:25 出处:网络
For applications which do not attract much traffic, the initial startup can take many seconds, but static HTML pages appear almost instantly.

For applications which do not attract much traffic, the initial startup can take many seconds, but static HTML pages appear almost instantly.

So my idea is to put some information on the static index.html and run an asynchronous warmup request from Javascript in the background. So if the browser hits index.html, the script w开发者_高级运维ould 'wake up' the GAE application while the user is still busy reading the information on the home page.

My question is: how could I dynamically render a 'loading ...' message from a background Javascript using jQuery? Or, to keep it very simple, just run a GET request and discard the result.

Could I simply add

jQuery.ajax("non-static-url");

to the jQuery(document).ready(function() ... code?


I would do something like this:

<script>
$(document).ready(function() {
  $.ajax({
    type: 'GET',
    url: '/url_here.php'
  });
});
</script>

If you wanted to have a loading message that disappeared when the warm-up was done, just render the page with an element like this:

<span id="loading-msg">Loading...</span>

and change the jquery ajax request to have a success handler, like this:

<script>
$(document).ready(function() {
  $.ajax({
    type: 'GET',
    url: '/url_here.php',
    success: function() {
      $("#loading-msg").remove();
    }
  });
});
</script>
0

精彩评论

暂无评论...
验证码 换一张
取 消