Trên "Google+ Sign-In for server-side apps" trang trợ giúp, trong "Bước 3: Bao gồm các kịch bản Google+ trên trang của bạn" đoạn sau đây được đề nghị:Tại sao phải chèn động tĩnh JS?
<!-- The top of file index.html -->
<html itemscope itemtype="http://schema.org/Article">
<head>
<!-- BEGIN Pre-requisites -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js">
</script>
<script type="text/javascript">
(function() {
var po = document.createElement('script');
po.type = 'text/javascript';
po.async = true;
po.src = 'https://plus.google.com/js/client:plusone.js?onload=start';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(po, s);
})();
</script>
<!-- END Pre-requisites -->
</head>
<!-- ... -->
Bây giờ, những gì SCRIPT thứ hai dường như làm:
- tạo thẻ SCRIPT mới, với nguồn tĩnh
- chèn ngay lập tức, trước thẻ SCRIPT đầu tiên trong tệp.
Bây giờ, câu hỏi của tôi là GÌ? Ý tôi là, sẽ không thực hiện:
<!-- The top of file index.html -->
<html itemscope itemtype="http://schema.org/Article">
<head>
<!-- BEGIN Pre-requisites -->
<script async src="https://plus.google.com/js/client:plusone.js?onload=start"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<!-- END Pre-requisites -->
</head>
<!-- ... -->
cũng đạt được điều tương tự? Tại sao chức năng trình bao bọc thêm này chèn tập lệnh?
Thuộc tính 'async' có vấn đề hỗ trợ. Nó sẽ không hoạt động trên IE <= 9. Xem http://stackoverflow.com/questions/1834077/which-browsers-support-script-async-async – bfavaretto