Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Robin Hansen 135 posts 368 karma points
    May 30, 2017 @ 08:26
    Robin Hansen
    1

    Clientdependency: Add 'async' attribute on 'script'tag

    Im' struggling with Clientdependency on my site - I think it has very great potential.

    It is essential for me to have an 'async' attribute on the script tag for the bundled and minified javascript. (Only when not running in Debug mode).

    I tried using both regex and Replace() methods on this @Html.RenderJsHere() with no luck.

    I cannot use Html tag attributes as described in the Documantation.

    If I don't solve this I'm affraid I'll have to abandon using Clientdependency and find an alternative... :(

  • ivan 41 posts 182 karma points
    Sep 19, 2022 @ 15:11
    ivan
    0

    Hi Robin,

    Did you find any solution on this?

    Thank you

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Sep 19, 2022 @ 22:14
    Chriztian Steinmeier
    0

    Hi Robin,

    You mention that you cannot use HTML tag attributes — do you mean that it doesn't work, or that you don't have access to the code that writes it?

    /Chriztian

  • Robin Hansen 135 posts 368 karma points
    Oct 26, 2022 @ 07:45
    Robin Hansen
    100

    Hi all. This is a very old question, but as I recalled, the reason for not being able to use the HTML tag attributes, was because I was bundling and minifying my .js files in production environment only, and therefore could'nt use the 'async' attribute while developmenting on my local maching. Then my .js script simply broke while being loaded asynchronically.

    As I recall I created this little helper method to cope with my problem:

    public static object CdfAsync()
        {
            if (!HttpContext.Current.IsDebuggingEnabled)
            {
                return new { async = "async" };
            }
    
            return null;
        }
    

    I hope this answer will be helpfull... :-)

Please Sign in or register to post replies

Write your reply to:

Draft