A little bit of experience doing the front end knows that you can reduce the number of requests by merging small images.
The earliest possible use of tools such as FW, PS to manually merge,
The shortcomings of this way do not spit groove, low efficiency, maintainability and so on ....
Some very powerful people, often develop a very powerful program to solve repetitive labor,
1. Https://github.com/iazrael/ispriter
2. http://www.uini.net/?p=870
3. http://csssprites.org/
4. More ...
I've learned a little bit about these tools, but in the end I think it's Better (smartsprites) (http://csssprites.org/)
Personally think it's good:
1. Simple grammar, flexible control;
1 |
/** sprite: icon-14; sprite-image: url(‘../images/components/icon-14.png‘); */ |
First, define a merged picture, define the content including, merge the identity, merge the image to generate the address, and more parameters, such as: Portrait or horizontal merge, whether the name of the image is automatically generated ....
12345678 |
.icon-add -14 { background-image : url ( ‘@{bg-components-srpite-url}icon-add-14.png‘ ); /** sprite-ref: icon-14;*/ } .icon-batch-delete -14 { background-image : url ( ‘@{bg-components-srpite-url}icon-batch-delete-14.png‘ ); /** sprite-ref: icon-14;*/ } |
You only need to add a specific annotation syntax after the normal gackgrund-image, Sprite-ref point to the starting sprite definition, identify the small graphs that are merged onto the same map,
This also has more parameters, such as: Position way, margin value, etc...
This seems to be not very simple and clear, completely do not destroy your original writing, just add comments!
2. Based on the cmd command, any program can invoke the
1 |
smartsprites.cmd --root-dir-path xxx --output-dir-path xxx --css-file-suffix "" |
Specify a CSS file directory, specify an output directory, specify a CSS file generation suffix
Of course, the goods are also flawed:
1. Java-based, so the JRE must be required;
2. The generated CSS file can not directly overwrite the CSS file, so it requires two directories, a CSS source directory, a CSS output directory;
3. It is a CSS annotation syntax, such as using less compile will break its comment syntax, this I have to deal with Grunt-contrib-less-smartsprite
For more documentation, please visit http://csssprites.org/
Smartsprites Smart Batch Merge CSS Sprite chart