WordPress.org

Ready to get started?Download WordPress

Forums

AssetsMinify
[resolved] Problem with calling function from enqueued script. (6 posts)

  1. szaqal21
    Member
    Posted 4 months ago #

    Plugin has hardcoded "async" attribute for script tag in function footerServe() and when I want to call a function from minified asset (right after minified asset script tag)

    <script async="" src="https://xyz/wp-content/uploads/am_assets/foot-63d925416ac7d2177826e375e86529d2.js" type="text/javascript">
    <script type="text/javascript">
    functionCall();
    </script>

    I get an error about that the function is undefined.

    When I've removed async attribute from script tag every thing worked fine. Please add some option or a filter to give possibility to modify this behaviour.

    http://wordpress.org/plugins/assetsminify/

  2. Alessandro Carbone
    Member
    Plugin Author

    Posted 4 months ago #

    I'll consider this for the next release of the plugin.
    Btw it is not a best practice to embed js within HTML code.
    Bye.

  3. szaqal21
    Member
    Posted 4 months ago #

    I know but I don't think it is necessary to create a seperate JS file just to call some init functions like Shadowbox.init() that's why I'm embedding this in HTML code and several others init's.

  4. Alessandro Carbone
    Member
    Plugin Author

    Posted 4 months ago #

    You are right: it is not necessary.
    It is a best practice ;-)

  5. szaqal21
    Member
    Posted 4 months ago #

    But isn't including js code as separate files slower than including it in HTML (in cases like I mentioned above)? Could you give me some hints where to read more about it? I've read that it is better to limit the number of external files. Thanks

  6. Alessandro Carbone
    Member
    Plugin Author

    Posted 3 months ago #

    Hi, new version released v1.2.2.
    Now you can enable async from backend.
    Btw, yes if you include multiple js files it is slower than including in HTML, but the best solution to achieve good performance and clean code is to compress the scripts with 1 single file and not to embed js script directly in the HTML files.
    Yes, it is better to limit the number of external files using js compression and minification. AssetsMinify does all of this.
    If you like, please review my plugin.
    Bye.

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.