Originally posted on: http://geekswithblogs.net/SoYouKnow/archive/2011/02/21/sharepoint-for-newbie-developers-code-scope.aspx
So, I continue to try to come up with diagrams and information to help new SharePoint developers wrap their heads around this SharePoint beast, especially when those newer to development are on my team. To that end, I drew up the below diagram to help some of our junior devs understand where/when code is being executed in SharePoint at a high level. Note that I say “High Level”… This is a simplistic diagram that can get a LOT more complicated if you want to dive in deeper. For my lesson it served its purpose well. So, please no comments from the peanut gallery about information 3 levels down that’s missing unless it adds to the discussion. Thanks
So, the diagram below details where code is executed on a page load and gives the basic flow of the page load. There are actually many more steps, but again, we are staying high level here. I just know someone is still going to say something like “Well.. actually… the dlls are getting executed when…” Anyway, here’s the diagram with some information I like to point out:
Code Scope / Where it is executed
So, looking at the diagram we see that dlls and XSL are executed on the server and that JavaScript/jQuery are executed on the client. This is the main thing I like to point out for the following reasons:
XSL (for the most part) is faster than JavaScript
I actually get this question a lot. Since XSL is executed on the server less data is getting passed over the wire and a beefier machine (hopefully) is doing the processing. The outcome of course is better performance. When You are using jQuery and making Web Service calls you are building XML strings and sending them to the server. Then ALL the results come back and the client machine has to parse through the XML and use what it needs and ignore the rest (and there is a lot of garbage that comes back from SharePoint Web Service calls).
<update>
Marc Anderson made the excellent point that this is not always true. I was thinking along the lines of retrieving lots of data for a list and building a DataViewWebPart with it instead of doing the same thing in jQuery by calling SPServices to return hundreds of rows of data and building a fancy report out of it. You CAN get better performance using jQuery in the some situations because you can delay calls for data until you need it, limit data you want to retrieve with CAML and user input, and not execute a web service call if it’s not needed. Marc’s quote was “Good architecture is good architecture”… wise words…
So.. let’s say it another way… You can get better performance with jQuery over XSL if you can take advantage of the following:
- Delay execution of code to retrieve data until it is needed
- Avoid calling a method to retrieve data entirely
- Lesson the amount of data retrieved by user selection and CAML
Thanks again for the input Marc.
</update>
XSL and JavaScript cannot work together in the same scope
Let me clarify. JavaScript can send data back to SharePoint in postbacks that XSL can then use. XSL can output JavaScript and initiate JavaScript variables. However, XSL cannot call a JavaScript method to get a value and JavaScript cannot directly interact with XSL and call its templates. They are executed in their scope only. No crossing of boundaries here.
So, what does this all mean?
Well, nothing too deep. This is just some basic fundamental information that all SharePoint devs need to understand. It will help you determine what is the best solution for your specific development situation and it will help the new guys understand why they get an error when trying to call a JavaScript Function from within XSL. Let me know if you think quick little blogs like this are helpful or just add to the noise. I could probably put together several more that are similar.
As always, thanks for stopping by, hope you learned something new.
Families in Germany who are facing divers soundness problem, such persons can buy drugs from the Web without prescription. With the market flooded with divers web-sites selling sundry medicaments, purchasing medicines from th WEB is no longer a trouble for common man. Certain medications are used to treat infections caused by dental abscesses. Of course it isn’t all. If you’re concerned about erectile health problem, you probably know about Xenical and Hoodia. Probably either adult knows about Garcinia. (Read more PhentermineXenical). The symptoms of sexual health problems in men include improbability to have an hard-on sufficient for sexual functioning. Certain medications may add to sex drive difficulties, so its vital to cooperate with your soundness care professional so that the prescription can be tailored to your needs. Preparatory to capture Levitra or other preparation, speak to your dispenser if you have any allergies. Talk to your soundness care purveyor for more details. Preparatory to ordering this remedy, tell your physician if you are allergic to anything.