A better approach is to store the scripts as files that are included in CEWP just like the jQuery library itself. You can use a single document library to store the script files; but as some of your jQuery scripts will be more generic (reusable) than others, I would recommend using several managed document libraries based on script classification.
I like to classify the scripts like this:
- Unique: the script is unique to the web page
- Shared: the script is shared between multiple related web pages, typically for all view pages of a specific list
- Common: the script is common for unrelated web pages, typically for view pages for more than one list
In addition, any custom CSS style sheets you use in your scripts should also be stored in the script libraries. Remember to assign ”Read” permissions on the script libraries to the group ”Authenticated Users”.
Unique scripts need no script library as they are included directly in CEWPs. Really large companies should consider having a global script library that stores jQuery files used across all SharePoint web applications.
Add the include files in this order in a CEWP: jQuery, styles, common and then shared. Add any unique script after all included styles and script.
Try to avoid using more JavaScript files than strictly necessary, as many include files will impact the load time of the page.
Always use page relative (../path/file.js) or server relative (/path/file.js) URLs in the <script src= > attribute. See this post for how to get site relative URLs. Avoid using absolute URLs at all costs. The web application root site-collection is the "server" in SharePoint terms.
If you don't want to expose and manage the scripts in document libraries, you can always provision the script files to the [12] hive using a feature: SharePoint jQuery deployment feature. See this EndUserSharePoint post for more alternatives for managing include files.
Related slidedeck
No comments:
Post a Comment