jQuery in SharePoint 2013 Script Editor Web Part not Executing when Minimal Download Strategy (MDS) Enabled
A word of warning. If you have the Minimal Download Strategy (MDS) feature activated in your SharePoint 2013 site, you may have challenges executing jQuery from a Script Editor Web Part or in page code placement.
jQuery that is on page load seems to function, but if you try to execute from a button or click event, it will not execute and leave you with an undefined error tied to the function you attempted to execute. This may be due to the call to execute not being cached, while on page load jQuery events are. If this affects you, there are 2 1/2 options as follows:
1) Disable MDS and lose the benefits of caching
2) Edit the master page to include the jQuery references as listed in this post: http://www.gsoft.com/en/blog/sharepoint-2013-developing-with-the-new-mds-feature
2 1/2) Hope that Microsoft addresses this limitation with a hotfix or Cumulative Update
UPDATE: Previously, wrapping code in $(document).ready(function () { }); was not working, but appears to be functional now when using jQuery 2x. Please test!
My experience is that Java Script isn’t executed at all in page display mode when you forget the type=”text/javascript” attribute in the html script tag.
So when the “Minimal Download Strategy” site feature is activated alert(“test”); wont be exuted while the page is in display mode. It will be executed while the page is in edit mode. This is issue only occurs when the MDS feature is activated. Deactivating the feature the script is executed both in page display and edit mode.
Issue solved when you don’t forget to add the type attribute alert(“test”) will be executed both in page display and edit mode and isn’t dependent on the MDS feature activated or not.