Is it bad practice to create a CSS file for each screen?

Asked

Viewed 108 times

0

I find it more convenient and easier to maintain if I create a CSS file per screen. Is that a bad practice? The same can be done with JS files?

  • 6

    Define bad practice.

  • Something that goes against web development best practices.

  • 5

    That doesn’t mean anything.

  • Best practices define standards of code organization and files to facilitate understanding and maintenance of them. A bad practice would be to do something outside of these standards and to leave the application disorganized internally, so that the lives of other people, who go tampering with your code, become more difficult.

  • 1

    Mainly based on opinions, right?

  • There’s no way around it, @jbueno. If it’s not, it’s a big discussion on the subject.

  • @Hiagomachado But it still depends on a starting point. Understand that good practice for me and my team can be bad practice for you and your team. Not to mention that it depends on design, specifications, how you want it to work. Have you heard that there is no "cake recipe" to program? Well, then, it is (also) what this phrase talks about. This question is invalid by this simple fact, good practice depends on who sees and how he sees. You will hear a lot about good practices and a lot of the people who cite it is because they want to invent a rule without needing to base.

  • It’s not based on opinions if you have a context, a plausible explanation of what you want, what you’re getting at. You’d need to see where you saw this, or if you pulled it out of your hat, if you see any problems, indicate what you’re doing better, maybe you’re more open-minded than you think.

  • 6

    If you look at it well, "bad practice" and "good practice" don’t exist. It’s synonymous with "I don’t know what I’m doing, so I’ll copy what they say". Either you have a real reason, or you don’t. If it has, it is not good practice, but knowledge (and the reason to do or not comes from this knowledge, and not from "practice"). If you have no real reason, it’s a guess, because every case is a case. Perhaps if you put a more specific context in the question, an appropriate technical answer is possible.

  • See there you might find something ... http://stackoverflow.com/questions/2336302/single-huge-css-file-vs-multiple-smaller-specific-css-files

  • I think this doesn’t fit into a bad or good practice, but it will give you an additional job. It can make it harder to reuse classes as well

  • Read this post https://answall.com/questions/67499/stylusruffles para-cada-p%C3%A1gina-ou-somente-uma

  • As you do on the server side, maintaining a level of file organization and content per file, with CSS and Javascript is no different. You can develop the visual style of your website and structure the CSS rules into several files, each with reference to a particular part. Ex: For structure, .css structure For navigation, navigation.css For form elements, Forms.css

  • It’s all a matter of opinion. My opinion is that you find it more practical to repeat code if you have a CSS file per page and there is something common between them.

  • I usually create a css that will have the common styles on all pages (usually used in templates), then the css that each page needs. In the end I compile all these css in one mining everything including.

  • It’s clearly bad practice and I’ll tell you why. 1- Makes it difficult to maintain code. Imagine that it style the H1 element in the same way all over the site. When you decide to change the look of H1 you will have to change in all the files. This goes against the concept of code reuse. 2- Each new file will generate a new HTTP request and when less HTTP request is better. Once the css file is downloaded it will be cached for the other pages. It will only be a request. And logical people what bad and good practices there are. There are tons of books and studies about it.

Show 11 more comments

1 answer

2


Look. I am also of the opinion to do what you think is best for you, but if you want a light on what is considered "best", there are those who will talk about what is more cost/benefit to your page.

In this link, it analyzes amounts of sending and receiving data and concludes that it is best to attach external files only if they have more than ½KB, otherwise it is better to join all or write inline.

But anyway, he says that the weight for the page is not so significant. The best to do accordingly, is what is most comfortable for you. As they said, good and bad practices are relative.

But now, in my opinion, if you are going to divide your sheets by screens, I still think you should have at least one main sheet for basic classes that you will repeat on all your screens.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.