Search

  • Home
  • Screencasts
  • Speaking
  • Downloads
  • Consulting Services
Browsing: / Home
Shortlink

How to: avoid duplicate load of jQuery, or else!

By Yaroslav Pentsarskyy on May 18, 2013 in sharepoint 2010, sharepoint 2013
Tweet

When you’re developing web parts and on demand solutions, in other words: you’re working on an individual component rather than a whole portal, you’re bound to run into this issue.

Scenario: you’re creating a web part for a client who runs existing SharePoint 2010 or 2007, or even 2013; also, let’s assume your web part uses jQuery to do something fancy – it’s hard not to use jQuery these days. If you client’s portal already calls jQuery in a master page and you’re registering jQuery in your web part again – those two will collide and you’re going to break the entire site.

One solution is, of course, to ask your client if they use jQuery, but that’s not always possible; especially if you’re working on a packaged solution you’re planning to distribute online. Also, even if they don’t use jQuery in a master page, how do you know that there is no 3rd party web part on the same page which calls jQuery.

So, the most reliable way to resolve this issue, is to verify if the jQuery has been registered and only register it when it’s not.

How?
Let’s say in your visual web part ASCX control, where you’d normally register jQuery, call the following script instead:


<script>
window.jQuery || document.write('<script src="/_layouts/MySolution/Scripts/jquery-1.9.1.min.js">\x3C/script>');
</script>

Above, we’re checking if jQuery is registered and if not, we output a string which registers it. In our case we’re sourcing the jQuery file from the local _layouts folder, but you can source it from online or a document library etc.

That’s it … here is the output of such call in case jQuery has not been registered:

jQuery loaded on demand

That’s it, now you’re safe against breaking your client’s site!

More tricks like this in my new SharePoint 2013 dev book.

Enjoy!

Share this on: Mixx Delicious Digg Facebook Twitter
Shortlink

How to: automatically package your SharePoint 2013 branding solutions with design manager

By Yaroslav Pentsarskyy on May 10, 2013 in sharepoint 2013
Tweet

There has been some buzz about SharePoint 2013 design manager and what is possible and what isn’t.
In this 7 minute video I’d like to demonstrate some of the basics of what you can do with the design manager.

P.S. More on packaging and solution deployment in my new SharePoint 2013 dev book.

Enjoy!

Share this on: Mixx Delicious Digg Facebook Twitter
1 2 … 338 Next »

Just Released! My SharePoint 2013 Book

My SharePoint books & DVD

Copyright © 2013 sharemuch.com.

Powered by WordPress and News.