What happens behind the scene, when a file is loaded with a file extension into a browser (like fox or opera)?

StackOverflow https://stackoverflow.com/questions/18948082

  •  29-06-2022
  •  | 
  •  

Question

What are browsers interpreting when the get a file extension upon load?

I try to mix html, svg and dtd (entities). I try to do that in a valid way. But now a stand for a problem that i dont understand. I did:

    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE html [
            <!ENTITY duration "3s">
            ...
            ...
    <div style='width:100%; border:1px solid black;'>high there</div>
    <p>toaster</p>
    <hr/>
    <svg width="600" ... 

and my 'page' displays well as intended, my Rubymine 'reads' the the file without any annotation.

as long as the file extenstion is SVG (ie. index.svg). If I change it to HTML - bad luck. The Page only looks a bit like it should. see both variants here:

as svg and as html

what happens now behind the scene when the browser "changes its mind" depending on a file exetension?

BTW my RumyMine tells me that there is something wrong with the file whe it has the 'html' extention (but not what).

I would preferre both: tell me what happens, and tell me what would be the correct way to do what i want.

Était-ce utile?

La solution

This has nothing to do with the browser processing the extension, but it starts with how the server processes the extension.

In fact, the spec says:

File extensions are not used to determine the supplied MIME type of a resource retrieved via HTTP because they are unreliable and easily spoofed.

When the page is served as http://keepitsimple-soft.com/question.html, your Apache server includes this HTTP header in the response: Content-Type: text/html, so the browser knows that it's an HTML page and uses an HTML parser to read it. The HTML parser doesn't process those entity definitions in the DOCTYPE, so it can't correctly interpret them in the SVG.

When the page is served as http://keepitsimple-soft.com/question.svg, the server includes this HTTP header in the response: Content-Type: image/svg+xml. In this case, the browser recognises the "+xml" part and parses the file using its XML parser. This does interpret the entity definitions, and can therefore handle the SVG fully.

As far as what you should do, you can either use XHTML and stick with the XML parser, or resolve the entity definitions before sending the page over the wire, in which case, your page should work with the HTML parser. (Though I haven't tested this.)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top