Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Asynchronous scripts

Started by Muut Archive 10 years ago · 3 replies · 513 views
10 years ago

Hello, does Grav asynchronous loading of scripts?

JS
<div id="vk_api_transport"></div>
<script type="text/javascript">
  window.vkAsyncInit = function() {
    VK.init({
      apiId: APP_ID
    });
  };

  setTimeout(function() {
    var el = document.createElement("script");
    el.type = "text/javascript";
    el.src = "https://vk.com/js/api/openapi.js?136";
    el.async = true;
    document.getElementById("vk_api_transport").appendChild(el);
  }, 0);
</script>

This code does not work.
Thanks.

10 years ago

I don't see how Grav would influence that at all. All Grav does is generate the HTML. Is that code making it to the final page?

10 years ago

As Perlkonig says, the JS you pasted creates an HTML <script> tag and fills the attributes. There is nothing that is Grav-related here.

10 years ago

Thank you for your attention. I think the same, but the example I took from the documentation from professional developers social network. A shorter version of the script, not asynchronous, it works. Just like the codes slow down the loading of the page.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1352 9 years ago
Archive · by Muut Archive, 9 years ago
2 935 9 years ago
Archive · by Muut Archive, 9 years ago
2 4064 9 years ago
Archive · by Muut Archive, 9 years ago
1 2949 9 years ago
Archive · by Muut Archive, 9 years ago
3 1119 9 years ago