0

In my application, I load a CSS files in the back-end (using Express.JS) and load it in the frontend. However, before sending CSS code to the front-end application, I want to:

  • Detect the user's browser;
  • Edit the CSS code accordingly.

For example, if user A uses Chrome, remove all lines that start with -webkit-.

How can I detect the browser and edit the CSS code with the best performance?

Note: My CSS code is formatted as beautified and not minified.

CMPSoares
  • 4,175
  • 3
  • 24
  • 42
thinkdiff
  • 11
  • 4
  • Can you explain the reason of doing this? `gzip`ing your css files before sending to browser will be faster and more effective – Denis Sheremet Nov 21 '16 at 07:11

1 Answers1

-1

We can detect User's browser by using user agents. Here is the URL to the answer regarding how to detect user agent.

Now, unless changing content of your CSS file, make 2 different files for different browser types and write some condition on your page CSS link tag accordingly.

Community
  • 1
  • 1
Aman Jain
  • 655
  • 5
  • 17
  • I can detect user browser agent but I want to edit the CSS code accordingly that I explained. – thinkdiff Nov 20 '16 at 16:11
  • You know one thing, editing CSS on the go will make a little delay in the response to the user. This is not recommended. Apart from that, the answer given by me is a suggestion and totally workable if you change the approach, so a negative vote is not justified. – Aman Jain Nov 21 '16 at 06:23