HTML and CSS Reference
In-Depth Information
Listing 4-15. Precedence Order of File Types Set by the qs Parameter
URI: logo
URI: logo.svg
Content-type: image/svg+xml; qs=0.8
URI: logo.png
Content-type: image/jpeg; qs=0.5
The qs value varies from 0.000 to 1.000 . Variants with a qs value of 0.000 will never be chosen. Entries of the
different variants are separated by blank lines that cannot be used within entries.
Explicitly setting paths to specific file variants is not feasible for larger sites with hundreds or thousands of files.
The second option for content negotiation on Apache servers is to use the MultiViews search feature, where the server
performs an implicit file name pattern match within directories and chooses from the results. MultiViews is a fine
option for eliminating file extensions that contributes to easy maintenance (in case new file versions will be used) and
optimal markup (because of shorter links). MultiViews can be enabled in the server configuration or .htaccess file
(Listing 4-16).
Listing 4-16. MultiViews Enabled
<Directory /home/www/example/htdocs>
Options + MultiViews
</Directory>
Now when the server receives a request for /images/logo and /images/logo does not exist, the server searches
inside the images directory looking for all files named logo.* , assigning MIME types based on the extension of each
file. The server then chooses the best match based on the preferences and delivers that resource. For example, let's
assume that the images directory contains the following file variants: logo.svg , logo.png , and logo.gif . When there
is a query for /images/logo , the precedence order will be considered in the answer to the query (Listing 4-17).
Listing 4-17. The Precedence Order of Image File Formats
Accept: image/svg+xml; q=.8, image/png; q=.5, image/gif;q=0.2, */*;q=0.1
When MultiViews is enabled, the server will search the referenced directory and deliver the image with the
highest quality (thanks to the highest precedence), in other words, logo.svg . This is achieved in a way that URIs in
HTML/XHTML files do not need to contain the file extension, which makes maintenance easier and reduces file size.
URIs can now omit the technology behind the resource. Since example.com/images/logo.svg becomes
example.com/images/logo , the logo embedding used throughout the site becomes <img src="logo"
alt="Company logo"> instead of <img src="logo.svg" alt="Company logo"> .
While a URI ending in .html or .php will probably remain the same in the near future, even widely used file types
might soon become obsolete or less frequently used within a few years. Flash animations ( .swf ) are often replaced by
HTML5 markup ( .html ), a PNG image ( .png ) by its SVG equivalent ( .svg ), and so on. As a consequence, all currently
created internal links of the site as well as the external links on other sites will be invalid.
The World Wide Web Consortium has mastered eliminating extensions in links. Even images of the site are
provided without extension in links (the files have extensions), so the links pointing to the file in thousands of web
documents should not be modified if the image will be changed, as, for example, from logo.png to logo.svg .
References with extensions remain usable; however, they do not allow the server to select the best of currently
available and future formats. With a type map declaration or with enabled MultiViews search [66], on the other hand,
raster images used for ages can be updated to their new, SVG versions in no time. The file name without the extension
is content-type generic , while file names with extensions are content-type specific .
Search WWH ::




Custom Search