Naming convention for assets (images, css, js)?

前端 未结 9 757
孤城傲影
孤城傲影 2021-01-29 20:33

I am still struggling to find a good naming convention for assets like images, js and css files used in my web projects.

So, my current would be:

CSS:

9条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-29 20:41

    I've noticed a lot of frontend developers are moving away from css and js in favor of styles and scripts because there is generally other stuff in there, such as .less, .styl, and .sass as well as, for some, .coffee. Fact is, using specific technology selections in your choice of folder organization is a bad idea even if everyone does it. I'll continue to use the standard I see from these highly respected developers:

    • src/html
    • src/images
    • src/styles
    • src/styles/fonts
    • src/scripts

    And their destination build equivalents, which are sometimes prefixed with dest depending on what they are building:

    • ./
    • images
    • styles
    • styles/fonts
    • scripts

    This allows those that want to put all files together (rather than breaking out a src directory) to keep that and keeps things clearly associated for those that do break out.

    I actually go a bit futher and add

    • scripts/before
    • scripts/after

    Which get smooshed into two main-before.min.js and main-after.min.js scripts, one for the header (with essential elements of normalize and modernizr that have to run early, for example) and after for last thing in the body since that javascript can wait. These are not intended for reading, much like Google's main page.

    If there are scripts and style sheets that make sense to minify and leave linked alone because of a particular cache management approach that is taken care of in the build rules.

    These days, if you are not using a build process of some kind, like gulp or grunt, you likely are not reaching most of the mobile-centric performance goals you should probably be considering.

提交回复
热议问题