Search code examples
javascripthtmlamp-html

AMP how to include javascript in page and apply functions from this script


I've been trying to include a javascript file in AMP page but it fails each time i tried

<amp-iframe width="200" height="100px" 
                        layout="responsive" sandbox="allow-scripts allow-same-origin"
                        src="https://laraflat.000webhostapp.com/public/js/index2.js">

</amp-iframe>

but it fails to load the functions inside this script


Solution

  • AMP Prohibits the use of external javascript libraries. You can only make use of the native AMP component's script.

    JavaScript is powerful, it can modify just about every aspect of the page, but it can also block DOM construction and delay page rendering (see also Adding interactivity with JavaScript). To keep JavaScript from delaying page rendering, AMP allows only asynchronous JavaScript.

    For more information visit here