I have a newer blog post about MDS, that provides a much simpler solution. Please check it before reading further.
Minimal Download Strategy (MDS) is an important feature in SharePoint 2013. It lets you download only a page delta, only changes. There is still issues with the MDS and custom scripts and almost no documentation on msdn or technet. In this blog post I want to learn more about adjusting custom scripts for MDS. As in my previous post, I want to take a real problem and try to solve it. The goal is to find a solution, not nececerilly the most optimal solution, at least for now.
Global Navigation and MDS
Recently I read in the Waldek Mastykarz' blog about how to create a Global Navigation using Managed Metadata and knockout.js. These are two posts which cover this solution, where you can learn a lot from:
I wanted to try it out in my environment and test it in an MDS-enabled site. As a first step I configured it in a site without MDS. There were no problems to get it working in a site without MDS, except some changed I had to make (The final code is available on my github repository):
- sp.js had to be loaded, because it wasn’t loaded. I added: SP.SOD.executeFunc(“sp.js”, “SP.Utilities.Utility”, …)
- The script didn’t need to load the navigation in modal dialogs and other views with hidden suiteLinksBox
I added this to the
Enabling Minimal Download Strategy
The Global Navigation works! Now it is time to enable Minimal Download Strategy. My site is a team site, so I can go to “Manage Site Features” and enable it: And… it stopped working, of course. Now the actual work begins. While troubleshooting, I discovered this:
- MasterUrl and CustomMasterUrl have to be the same Master in order to work, otherwise MDS fails
- with MDS knockout is not loaded, the Mavention.GlobalNavigation does not run
- Moving the code outside the SharePoint:AjaxDelta control in the masterpage doesn’t affect anything
I tried almost everything. The code started to run in MDS after these changes in the masterpage:
- the plain
<script> tags were converted to
- In the masterpage I ran the
- Create a function (not an anonymous) and call it directly in the end of the script file
- Use a ScriptLink instead of a plain script tag
[…] blog I learned I had to register my namespace. His blog led me to Anatoly Mironov’s blog about wrapping your code in a $global wrapping function. Basically I wrapped my entire code in […]
Thank you for your post it was very helpful ;)
I have just done RegisterModuleInit as mentioned in (https://blogs.technet.microsoft.com/sharepointdevelopersupport/2013/02/08/register-csr-override-on-mds-enabled-sharepoint-2013-site/#comment-14915) blog and it worked for me in SP2013 and working seamlessly. But when I deployed same code I SP2016, its not working for me. Did u tried ur code with SP2016 ?