Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why separate vendor CSS & JS from custom CSS & JS in a workflow?

I've been trying to determine the reasoning behind what seems to have become the standard practice in Front End workflows of separating vendor JS & CSS from custom JS & CSS. I'm not sure what the benefits are over the disadvantage of an extra HTTP request, it would seem cleaner to just have a single CSS & JS file rather than having vendor.css, main.css & vendor.js, main.js.

Can anyone shed some light on this?

like image 922
sjm Avatar asked Sep 02 '15 23:09

sjm


People also ask

What is a CSS vendor prefix?

Jessica Kormos is a writer and editor with 15 years' experience writing articles, copy, and UX content for Tecca.com, Rosenfeld Media, and many others. CSS vendor prefixes, also sometimes known as or CSS browser prefixes, are a way for browser makers to add support for new CSS features before those features are fully supported in all browsers.

Why should we separate css from HTML?

Why is it important to separate CSS from HTML today? Assume we are not under legal obligation to make our web app accessible (since accessibility would inevitably lead to no-JavaScript version), and that the app is already using JavaScript extensively for its core features.

What happened to vendor prefixes in browsers?

Browser vendors slowly began to move away from prefixing, favoring feature flags inside the browser settings instead. It appeared that the problems created by vendor prefixes would fade away in time. The question is: has that time come yet?

Why does Firefox use different CSS Values than other browsers?

Also, Firefox uses different values than the standard ones. The reason that you always end your declaration with the normal, non-prefixed version of the CSS property is so that when a browser does support the rule, it will use that one.


2 Answers

Vendor code typically changes less frequently than your application's code. Thus as you update your application, the vendor code can remain unchanged and cached in your user's browser.

In the scenario where vendor code is bundled with application code, the user has to download all of the vendor code every time you update the application.

The extra HTTP request from the separate vendor bundle is mitigated by the fact that the user will download less code on each application update.

like image 143
Sunil D. Avatar answered Sep 21 '22 22:09

Sunil D.


I can think of two reasons.

  1. Hosting vendor code separately from your code (e.g. Google Hosted Libraries)
  2. Separation of concerns: the vendor code might be large and is updated independently of your custom code. Maintaining your code in a separate file avoids the need to put vendor code into your source control, makes it easier to navigate your code, makes it easy to upgrade to new vendor code since you know for certain the vendor code has not been tweaked.

Especially since you tagged the question with grunt, the end user might never see this change since you can merge vendor and user styles/scripts during the build.

However, if vendor code is large and changes infrequently, you do get a caching benefit from having a rarely changing, large vendor file accompanied by a small, fast changing custom code file. For large sites that do not use a CDN (hopefully, not yours), the impact can be noticeable.

like image 41
MaxVT Avatar answered Sep 23 '22 22:09

MaxVT