Using the Client Resource Management (CRM) to inject CSS/scripts through DNN fails if those need to run after the page loads


Currently, if a module uses cache and it uses the CRM to register scripts in the backend code, the script will only be loaded once on the first load. Subsequent requests will fail to load the script since it does not run the backend until the cache is cleared.
Additionally, even if the script is registered using the control (ascx) instead of the backend (ascx.cs), it will only load the first time in the right location (force provider) and it will load on the top of the page in all subsequent requests until the cache is cleared.

Recommended reading

We recommend that you take a look at this article before looking at the solution


This is a current limitation of the software, however, there are some possible workarounds: 

1. Inject the script directly without using the CRM in an HTML module or the skin.
2. Register the script in a new skin layout, and then use that layout only for the page with your module (to avoid adding overhead to the other pages)
3. Add a control after the module that does not use caching and which sole purpose is to register the script.

Versions: DNN 9.0+

Credits: Manuel Gonzales



Please sign in to leave a comment.