Why aren't PHP files used for (custom) CSS and JS?

后端 未结 8 1192
旧时难觅i
旧时难觅i 2020-12-15 22:27

Why don\'t people make .php files for their CSS and JavaScript files?

8条回答
  •  心在旅途
    2020-12-15 22:48

    The bad sides: plenty, but to name just a few:

    • It'll be dead slow: constructing custom stylesheets for each request puts a huge load on the server, not something you want.

    • Designers create CSS files, programmers shouldn't (in some cases shouldn't be allowed to). It's not their job/their speciality.

    • Mixing JS and PHP is, IMHO, one of the greatest mistakes on can make. With jQuery being a very popular lib, using the $ sign, it might be a huge source for bugs and syntax errors. Besides that: JS is a completely different language than virtually any other programming language. Very few people know how to get the most out of it, and letting PHP developers write vast JS scripts often ends in tears.
      JavaScript is a functional OO (prototypal) language. People who don't full understand these crucial differences write bad code as a result. I know, because I've written tons of terrible JS code.

    • Why would you want to do this, actually? PHP allows you to change all element's classes while generating the page, just make sure the classes have corresponding style rules in your css files and the colours will change as you want them, without having to send various files, messing with headers and all the headaches that comes with this practice

    If you want more reasons why you shouldn't do this, I can think of at least another few dozens.
    That said: I can only think of 1 reason why you would think of doing this: it makes issues caused by client-side cached scripts less of an issue. Not that it should be an issue in the first place, but hey...

提交回复
热议问题