Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

There's been a lively conversation (such as it can be in 140 chars) lately about whether it is better to put CSS files on the disk in the _layouts folder or to store them in a Document Library in the Site Collection. This seemed like a good place to post the topic to allow some longer discussion about it.

As for me, I always prefer to avoid putting anything on the disk if I can avoid it. I prefer a Document Library for the CSS. There are many reasons for this, but here are some: versioning, fine-granied permissions, approval processes, they are a part of a Site Collection backup, touching the server can lead to problems, etc. I also don't believe that files on the disk will be served up any faster than files in SQL if SQL is managed correctly.

What's your opinion? Weigh in!

share|improve this question
add comment

15 Answers

They should be in a site collection so that css designers can change them without having to go through a system modification process with the server admins. Even though the files cannot hurt anything, typical sys mod procedures require multiple approvals and scheduling which is excessive and unnecessary for style sheet changes.

share|improve this answer
add comment

There are some differences between the file system (_layouts) and libraries from a caching perspective. Chris O'Brien has a good article that touches on these - Optimization, BLOB caching and HTTP 304s.

share|improve this answer
    
Thanks Nick, guess we were typing at the same time there :) –  Chris O'Brien - MVP Apr 6 '10 at 21:25
add comment

At a high level, it often depends on your view of the function of the files:

  • site 'infrastructure' which is critical to branding (e.g. public-facing WCM). Here you might choose to store on the filesystem as users/content authors will never be modifying the files
  • content specific to an individual site, open to customization (e.g. a team site in a collab portal). Here you might store in a library as power users most definitely will want access to these files.

A note on performance - BLOB caching is generally required to get equivalent performance from document libraries and the filesystem - there's more to it than just SQL. Last year I did some optimization work for a public-facing airline site with poor performance, and I found that a big factor was CSS/JS files coming from the Style Library. The issue turned out to be a bug in SharePoint's BLOB cache framework which meant the files were being served with incorrect headers, meaning a HTTP 304 roundtrip occurred needlessly for every file before it was served from the browser cache. The details of this are in my posts:

The conclusion to all this was that it is possible to get good performance from files stored in such document libraries, but there are a couple of hoops to jump through first. Maxime documented these in BlobCache, Style Library, and anonymous users

share|improve this answer
    
Agreeing with you, imo css + images + js files should be stored on the filesystem for performance reasons when you are deploying a public facing site (like a portal). Unless the client/customer explicitly asks for the need to modify the css using SPD or any other tool I won't opt for the style library mode. –  Anonymous Apr 7 '10 at 12:44
add comment

Another reason to let your CSS files, JavaScripts, images etc stay in the Style Library, Site Assets or other document library is Sandboxed Solutions in SharePoint 2010. If you plan or even thinks of moving your solution to a user code solution then the file system is a no go.

share|improve this answer
add comment

I've stored CSS in the Style Library for many implementations and have not had load time problems. I find it better than storing on the file system for several reasons:

  1. The library is version controlled, with a check-in/out process and rollback. The file system has none of these.
  2. The library is content, which gets distributed across all web heads. The file system requires deployment to all web heads separately, which can cause problems with versioning if, say, you forget to deploy to one of your 4 web heads. Maintenance, especially with a consulting client, is easier with a library because of this.
  3. You can view the library and edit the CSS within SharePoint Designer. You cannot view the _layouts directory in SPD.
  4. The library allows you to work from your local box in SharePoint Designer, whereas the file system requires you to remote into the server.

I will explore the Chris O'Brien's point about the BLOB caching and 304s to make sure performance cannot be improved, but like I said, I've not noticed any performance hits attributable to CSS storage in a document library.

share|improve this answer
add comment

My personal preference is to store this type of asset on disk since it typically forms part of the solution as a whole, which includes binary assemblies, web part registration config etc. and doesn't typically change in isolation (except to fix layout bugs).

I do agree that there are advantages in storing these assets in the content database though – it makes them simple to edit, version and deploy. With an out of the box SharePoint configuration you are however going to suffer performance penalties, both from the perspective of database server load and network time due to cache configuration issues.

In addition to accelerating page load times generally, Aptimize solves all problems mentioned in this thread (including the 304 issue that Chris refers to) – database load and network time are reduced by intelligent server and client caching, and content changes are automatically picked up by the browser without having to wait for the cache expiry duration. Developers can keep source assets in the content database and push changes easily, and browsers of the site will only ever request these assets again when they have actually changed.

Derek. CTO, Aptimize

share|improve this answer
add comment

I posted this exact question a few years ago and got 2 detailed responses back, one being from Andrew Connell! Both responses were of similar view point.

Andrew said:

Anthony- The way I do it is all content goes in one of the three special libraries in each site (Images/Documents/Pages) and all branding stuff goes inside the Style Library. I am against putting files on the server in the LAYOUTS folder or anything inside the 12 folder. Ideally, use a Feature to provision these files into the Style Library just as you do with master pages and such. The Style Library is for branding files (CSS, images).
-AC

The other response I received was from Jason Huh : http://www.jyhuh.com/blog"

Jason said :

Both approaches will work, but I think deploying to "Styles Library" and "SiteCollectionImages" (or Content Database with "ghostableInLibrary" mode) make more sense than to TEMPLATE\LAYOUTS... folder (or unghosted in file system). Deciding the location of images might be a big deal, but it is a big deal for the location of style sheets because you have to think about updating style sheets after deployment. There are couple of benefits of deploying to SharePoint Content Database with ghostable mode over deploying to the file system under LAYOUTS.

  1. Deploying to Content Database supports versioning. You will be able to update style sheet, xslt, master page, etc. from SharePoint UI or SharePoint designer, keep different versions and roll back to previous state easily.
  2. Fewer issues with SharePoint blob caching. Depending on folder locations inside LAYOUTS, files deployed to LAYOUTS folder may not work with SharePoint blob caching, and this might result in annoying glitches. You would not experience this symptom if files are to use out-of-the-box Master Page gallery, Styles Library, SiteCollectionImages, etc.
  3. Less footprint. Files deployed to LAYOUTS folder will be available to all SharePoint web applications in the farm including SharePoint central admin, MySite, SharePoint Service Provider, etc. This is typically not what you would expect. Deploying to SharePoint Content Database will make sure that the footprint of files will be limited to a specific FEATURES folder and a Content Database.

Hope this helps. Anthony

share|improve this answer
1  
Nice to see that Andrew and I agree on this, even if his response is dated. –  Marc D Anderson Apr 7 '10 at 11:49
add comment

The only problem I perceive is that what happens in the approach where you deploy the CSS via a feature into Style Library (or somewhere in content) is that it puts v1.0 up there.

Designers then short cut this and just use SharePoint Designer and edit them directly breaking the inheritance to the artifact deployed to the SharePoint Root (file system) RATHER than going back and editing the CSS in the feature and upgrading the Solution Package in source control.

This is mainly due to the effort involved for a Designer to use Visual Studio and relying on admins. This does get easier now with F5 in Visual Studio if they can work locally and then finally send it to the admins to deploy to the UAT/Prod farms. They can also, as @wictor pointed out, deploy this themselves as a sandboxed solution if they like too. Again, to do the F5 they need a local, be great if F5 would push to UAT etc.

I tend to push the WSP route for performance and the fact that more often than not when you do CSS stuff you are also deploying other bits like Master Pages, Page Layouts that are all dependent on each other and should be deployed the same way.

share|improve this answer
add comment

Looks like someone already posted my $.02 :)

I don't like them in _layouts... I prefer them in the Style Library. Want my long winded response? Read my article on MSDN: http://msdn.microsoft.com/en-us/library/dd221375.aspx

share|improve this answer
add comment

I've always put my javascript and css files in a document library where they can be called relatively from a script. The only reason I would say putting them in the _layouts folder is if you plan on implementing the css files into more than one site collection.

Why bother? If the styling for CSS is going to stay with the site collection, it's more logical to have it close to the site collection in the database, rather seperate on a VD. When the site collection gets backed up, so does the CSS/scripting. Makes sense.

share|improve this answer
add comment

In general I have had a lot of luck storing them in doc libs. So far I have not seen any issues with loading and the sites work fine. Most of the work I have done has led me down that path and it seems to be working well. Other's have already gone over most of the pros and cons and I have to agree!

share|improve this answer
add comment

I have found it easiest to keep my custom site logos, favicon, and custom CSS externally on a test server for our public facing websites. That way I can just use an absolute URL to these items where needed, and I only have to go to one place to update them.

For example, after a quick update to the CSS file I just have to save it in one place, rather than re-deploying to the various Style Libraries. I don't like to access the SharePoint server unless I absolutely need to, I'm superstitious that way.

We don't do any custom coding, so this has been the best solution for us so far.

share|improve this answer
    
What happens when you need to whack the test server to get it up to production level? Or isn't it that kind of test server? What happens when the test server is down? –  Marc D Anderson Jul 16 '11 at 1:20
add comment

Just about to deploy a SP 2010 instance and it was a good read. But i think i would put the images in the Layouts page and the scripting and css files in a sharepoint library. 1) Images won't be updating much.So goes to a file system 2) Scripting,css etc would be in a SP library and it would be easy to modify and save using SP designer.

What do you guys think?

share|improve this answer
    
There's no one answer to this question. In my mind the most important thing is to be extremely consistent and make it part of your programming practices in your governance. –  Marc D Anderson Aug 19 '12 at 14:23
add comment

in most cases for the single site collection i store the CSS, images and JS in a sub folder in style library. If your should be able to use SPD to work with this kind of files it's a good way and you have versioning and permissions regarding to this. In other cases if this files should be at the webapp level and if the CSS file are a part of a branding VS solution and other kind of stuff are provisioning to the filesystem I think the CSS should follow the same pattern. It could also be a question for the customer, should this be handle as an alternative CSS and the customer should be able to update the CSS the filesystem is maybe not the best solution to those who have not access to the server. / C

share|improve this answer
add comment

When developing from Visual Studio I belive that putting the files in the file system always is the best solution when possible. It is much faster and easier to update and the performance is much better than picking it up from the SharePoint DB.

Also when branding a corporate site, no matter if it's a public facing site or an intranet, the company has spent a lot of money to make sure that their corporate identity shall be intact and therefore these files should not be changed by anyone except for these people who has the knowledge and skills to actually do so. Putting them in the style library, image library and so on often gives the wrong people the power to do more harm than good by changing design from a personal point of view and not from the identity that the company wants to be spread around the world and inside the walls of their corporate senses.

I agree that sometimes the end user wants to have changes in the design in some places but then I vote for having a number of sets with ready made styles that the user can choose from.

Also from a deployment perspectiv, what happens to these files in the style library that has been changed and we want to do a redeploy of the design? Either they stay intact and the redeploy will not have an inpact or the will be overwritten and the changes that has been made will be gone.

Love reading about all this btw .. great posts !! .. :)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.