A running list of best practices. All our programmers should read this and understand each item.
This list formed the bais for a presentation at VueJS LA meetup on January 14, 2020 by Drew Baker. You can see the slides here.
- No CSS resets
- Be semantic - call things what they are. Name your component what the filename is, and give it a class that matches.
- In Vue templates, use components like
<component-name/>
not like<ComponentName>
. - Avoid use of element name selectors in CSS. Don't use
h2
, give it a.title
class instead. - In general avoid use of CSS pseudo elements like
:content
,:before
,:after
. Except for list bullets or underlines. - No use of floats
- Don’t use
#
ID’s unless using for JS selectors or actually need page anchors. - Use a central z-index location for major structural components, increment by 100’s
- For component level z-index set top level to 0 and increment by 10
- Use positioning sparingly. In general most people over use
position:absolute
. - If using useless markup to get a desired style, you’re doing it wrong. For example wrapping divs, centering divs.
- Define CSS for active and hover states at the end of component, followed by breakpoints at end of file please!
- When using SCSS if you’re going more than 2 levels deep, question yourself. Think of the top level element class as a namespace, so things in it don’t need namespaces too.
- Never use background-images, use object-fit with src-set instead.
- For class names use is-{state} and has-{feature} or not-{type}. Like is-active, is-opened, has-video, not-case-study, is-active.
- Common element class names: block, grid, panel, menu, overlay, meta, title, section, section-title.
- Margin top/bottom, padding left/right.
- Use lodash! You’re not getting points for using map() and filter() in inventive ways!
- Don’t fight the browser - scroll, events, URLs etc…
- With Nuxt-Link or Router-Link use relative paths from the root (start with a
/
). - Use white spacing in your templates.
- Order your CSS in the same order your markup is in. Top to bottom as coded.
- A
switch
statement is better than a lot of if-else conditions - This is how you do forms in Vue.
- 100vh doesn't work great on mobile. See this for how to do it right.
- Don't use icon fonts, use SVGs. SVGO is a good tool for optimizing SVGs.
- Be sure to include the
viewBox
attribute.
- Be sure to include the
- This is a good clean sample component to study.
- If your component accesses $store or $route directly, you're doing it wrong. Use props and events instead.
- We care about Chrome, Safari and Firefox in that order.
- You can write breakpoints without needing a media query generally. Often using width and max-width is enough. Good break points will really just be font-size and reducing columns perhaps.
- Understand collapsible margins!
- Understand intrinsic ratio sizing!
- Understand when to use wp-content, v-html, v-text
- Clean up after yourself, don’t leave behind old code!
- Drew to show everyone how to build top-panel/bottom-panel style fixed sliding sites
- Really think hard about what can be a component. Makes a site so hard if you don’t use components.
- Know what components and tools.js we have in fuxt and our haus components!
- Don’t do things rough with the expectation of coming back to it. Do it right the first time, think it through.
- Add head() data for SEO as you build each pages. Sucks to do this at the end.
- Learn how to spot red flags. Long file? Deep nested CSS? Watching a lot of things? Lots of specific break points? Committing to the store a lot?
- Organize your windows into panels of editor and browser and dev tools.
- Use Prettier along with the linting tools built into fuxt.
- Demystifing Nth-Child in CSS
- Flexy Boxes Playground
- CSS Grid Generator
- 16:9 calculator
- Clippy
- Facebook OG debugger
- CSS Guide Lines - Best CSS guide there is
- Vue Style Guide
- The introduction to Reactive Programming you've been missing
- You (Might) Don't Need jQuery
- A Smashing Guide To The World Of Search Engine Optimization
- Good overview of ES6 destructuring
- A good book on how to write good CSS
- Use console.log() like a pro
- https://github.com/thejsway/thejsway
- https://www.oreilly.com/library/view/eloquent-javascript-3rd/9781492071198/
- https://www.modernjsbyexample.net/
- https://addyosmani.com/resources/essentialjsdesignpatterns/book/
- https://martinfowler.com/articles/refactoring-2nd-ed.html
- https://exploringjs.com/es6/index.html
- https://leanpub.com/javascriptallongesix