SharePoint Customization - My Best Practices Part - 1





In this post I will discuss a method, which I usually follow for my SharePoint front end customizations.

In SharePoint, unless you have the access and the permission to embed the JavaScript, jQuery and Styles in the master page, you might have to include these in each page using the content editor webpart. Initially most of us start writing the scripts in content editor. But by doing this, sometimes a jQuery/JavaScript/CSS might be initialized multiple times, which might make the code to not work(mostly this happens when jQuery is initialized multiple times).

To eliminate such problems instead of adding these jQuery/JavaScript/CSS in the html code editor of a Content Editor webpart, it is always a better practice to save the jQuery/JavaScript/CSS into a text file and create a document library in SharePoint and upload there.

You may ask me what is the purpose of doing this? Well if someone else apart from you edits the page by mistake and deletes the webpart (or) if for some reason your SharePoint admin have restored the page to a previous version, then all your effort is vanished, you might lose your scripts and styles.

Below are the steps I usually follow while working on SharePoint site front-end customizations.

1.      I usually create a document library in SharePoint and name it as "Scripts&Styles" and under which I create two folders named "Scripts" and "Styles" as shown below. It doesn’t matter if you have one single folder for both.



2.      Then I map this document library to my computer drive. How? See the steps below.
a.       Open "My Computer/ Computer" from your Windows OS.
b.      Click on empty space in the windows and find "Map network drive" at the top and click on it. (See below)


c.       Now a window pops out asking for the location to which it has to point.
                                      i.      Enter the Url of the document library in the folder textbox without the prefix "http:". Replace all '/' with '\'. So the url will be something like "\\domainName\sites\yoursitename\documentlibrary\"
                                    ii.      Check "Connect using different Credentials if your machine is not connected to the same domain Server as the SharePoint . i.e., check this if you are not logged into the system with the same credentials you used to login to SharePoint.


d.      Once finished, the SharePoint document library is one of your computer drive where you can edit save and create the documents.
3.       It is always a better practice to create an initialization script file  with all the "will be used" script links. My initialization file will look as following:



    Click here to go to the Part -2 of this post



      0 comments: