DNN Forums

Ask questions about your website to get help learning DNN and help resolve issues.

Where to add defer tag to pages/script tags

Sort:
You are not authorized to post a reply.
Page 1 of 212 > >>





Growing Member





    I used PageSpeed Insights to evaluate my home page performance. It stinks. One of the recommendations is to add either the deferred or async attribute to the script tag elements.

    https://web.dev/render-bl...p;utm_medium=unknown

    since these pages are stored in the database, i am not sure how to modify them as advised. the readout also advised moving non-critical css, js, and html imports inline. again, without direct access to the page, i am not sure how to accomplish this. i have looked around in the page settings, but nothing pops out.

    any recommendations on how to make these changes would be appreciated.






    Growing Member





      there are some hints in this line https://stackoverflow.com...nd#50883266 but i still can't make sense of it. i want to experiment with defer or async on my home page, but nothing in the responses gets me there.






      Growing Member





        i experimented a little with one of the methods shown in that aforementioned link and another on this forum - https://dnncommunity.org/forums/aft/286

        i first entered debug mode in the browser (F12) to see all of the files loaded by the home page. i then went to the server to edit default.aspx where DotNetNuke.Web.Client.ClientResourceManagement was already registered on the page as dnncrm.

        my code is no longer visible in edit mode so i can't clean it


         

        unfortunately, it caused my LayerGalleryPro (dnngo) slider to disappear. so i am not sure if i added the code in the right place. it would be nice if i could make these changes without editing code on the server. but more importantly, how do i make this work?

        <dnncrm:dnnjsinclude filepath="/Resources/libraries/jQuery/03_05_01/jquery.js?cdv=52" htmlattributesasstring="async:'async'" runat="server">

        <dnncrm:dnnjsinclude filepath="/Resources/libraries/jQuery-Migrate/03_02_00/jquery-migrate.js?cdv=52" htmlattributesasstring="async:'async'" runat="server">

        <dnncrm:dnnjsinclude filepath="/Resources/libraries/jQuery-UI/01_12_01/jquery-ui.js?cdv=52" htmlattributesasstring="async:'async'" runat="server">






        Growing Member





          Tony, I'm sure more knowledgeable individuals will chime in with the best answer, but I think you need to add that to the top of your theme (skin) file. /portals/_default/skins/NameOfYourThemeFolder/themepage.ascx






          Growing Member





            i think that may well in fact be part of the solution, especially for those scripts and css related specifically to the theme. but i will not comingle theme artifacts with dnn artifacts - there needs to be separate spaces where they each can handle their own concerns.

            on the other hand, you did lead me find some script tags which i can edit directly without using the library control i mentioned above - so thank you. i now need to determine if they represent files with which PageSpeed took issue.






            Growing Member





              Tony, most of us consider editing a theme instead of the core DNN files as the exact right way to separate our modifications from the actual DNN programming. That might let you be more free with your edits in there. The caution that I have in this idea is that if you later upgrade the theme, your edits might be overwritten. There is a simple solution for that too. Just copy your theme acsx page and give it a custom name. Then assign your site to that page instead of the original. Make all the changes you need to your new custom theme acsx file. Your custom theme page will not be overwritten with a theme upgrade any more.

              An alternative thing for you to investigate would be Will Strohl's Injection module. You can use it to dynamically inject your js links and more into your pages without changing the files manually.

              https://github.com/hismig...ection-02.00.02/wiki





              Growing Member





                It sounds risky to me. async in particular introduces a non-deterministic timing relationship between the script and the rest of the page. Non-deterministic is a posh phrase meaning that you cannot be sure it works just from testing it, because you cannot predict the timing.

                Knowing nothing about your actual problem, my first suggestion would be to get the script and the css properly cached in the browser. Not having to download it at all (after the very first page) will beat any async or deferred loading.

                See https://blog.httpwatch.co...es-for-http-caching/ and https://www.dynamisys.co....caching--Part-1.aspx

                Thanks,
                Richard
                www.dynamisys.co.uk





                Growing Member





                  Posted By RichardHowells on 22 Jul 2020 03:58 PM

                  It sounds risky to me. async in particular introduces a non-deterministic timing relationship between the script and the rest of the page. Non-deterministic is a posh phrase meaning that you cannot be sure it works just from testing it, because you cannot predict the timing.

                  Knowing nothing about your actual problem, my first suggestion would be to get the script and the css properly cached in the browser. Not having to download it at all (after the very first page) will beat any async or deferred loading.

                  See https://blog.httpwatch.co...es-for-http-caching/ and https://www.dynamisys.co....caching--Part-1.aspx

                  of course it is "risky" but web ranking companies don't care about that. i have discovered in my experimentation that using ClientResourceManagement  DnnJsInclude can cause page modules not to load at all. but it may well be that i am using it incorrectly. nevertheless, there is an ocean of articles advocating asynchronous loading of js scripts but it only works if loaded via src=. page optimization is a very huge undertaking because there are so many opaque aspects about the dynamic page loading.

                  cacheing is a concern, but most page and site rankers do not consider it exlusively, or it is only one part of the consideration. the initial raw load needs to be fast.

                   






                  Growing Member





                    Posted By Mark Buelsing on 22 Jul 2020 03:45 PM
                    ...
                    An alternative thing for you to investigate would be Will Strohl's Injection module. You can use it to dynamically inject your js links and more into your pages without changing the files manually.

                    https://github.com/hismig...ection-02.00.02/wiki

                    i do not want to dynamically inject links - these are not my scripts - they belong to dnn and dnn modules i am using - i simply want to optimize the existing processes and there are methods of doing so - i don't think i really know how to do it. the one technique of injecting deferred or async load attributes to existing script tags is the least instrusive method to me. it may or may not accomplish my goal of faster page load times, but i want to experiment with it since it so heavily advocated in the seo community.

                     






                    Growing Member





                      of course it is "risky" but web ranking companies don't care about that.


                      My point is that deferred or async loading of a script is part of the design of that script. Inflicting deferred or async loading on a script not designed for it is likely to have bad consequences.

                      If this is important to you please consider proposing and implementing a pull request for the DNN core that properly implements the feature and allows developers/designers access to the correct choice for their scripts. If there is general interest in the feature you will likely find people who want to work with you on it.
                      Thanks,
                      Richard
                      www.dynamisys.co.uk
                      You are not authorized to post a reply.
                      Page 1 of 212 > >>

                      These Forums are dedicated to the discussion of DNN Platform.

                      For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

                      1. If you have (suspected) security issues, please DO NOT post them in the forums but instead follow the official DNN security policy
                      2. No Advertising. This includes the promotion of commercial and non-commercial products or services which are not directly related to DNN.
                      3. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
                      4. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
                      5. No Flaming or Trolling.
                      6. No Profanity, Racism, or Prejudice.
                      7. Site Moderators have the final word on approving / removing a thread or post or comment.
                      8. English language posting only, please.

                      Would you like to help us?

                      Awesome! Simply post in the forums using the link below and we'll get you started.

                      Get Involved