Can someone tell me method to define the MIME-Type of a static XHTML File as text/html …. I don’t want to use php, asp.net…….. javascript would be ok
You shouldn't. Here's why:
Sending XHTML as text/html Considered Harmful (http://hixie.ch/advocacy/xhtml)
If you use XHTML, you should deliver
it with the application/xhtml+xml MIME
type. If you do not do so, you should
use HTML4 instead of XHTML. The
alternative, using XHTML but
delivering it as text/html, causes
numerous problems that are outlined
below.
Use your web server to do it. If you are using apache, create a file called .htaccess in the directory with the file and add this line:
AddType text/html .html
Related
My web application creates a zip file to download files related to a "Task" instance. This zip file can contain images, .pdf or .txt files, the filename created has the form "{taskName}.taskBundle".
To download the file, the web application use the following headers in the response (from Firefox Network monitor):
Content-Disposition: attachment; filename="task1.taskBundle"
Content-Type: application/zip;charset=UTF-8
The problem:
Using Firefox 84.0 (Ubuntu and Windows versions), the browser is replacing the '.taskBundle' extension by '.zip', so the downloaded filename is "task1.zip" instead of "task1.taskBundle".
I tried to download the same file with Chrome (87.0) and another Firefox versions (83.0, 82.0, 80.0, 74.0) and the file name is correct: "task1.taskBundle".
Maybe should I add another header to the response to prevent Firefox change the file extension?
I can change the Content-Type to 'application/octet-stream' but the checkbox "Do this automatically for files like this from now on." is not displayed in the download dialog.
Additional notes:
My app is written using Grails 3.3.9 but I think it is not a Grails issue because the response headers are sent to the client as described before.
We're fixing this in https://bugzilla.mozilla.org/show_bug.cgi?id=1684183 , but it'll likely not be before Firefox 85 (ie we won't be shipping a security / out-of-cycle dot-release fix just to address this issue).
A simpler workaround for your usecase would be choosing / standardizing on a specific mimetype for these "task bundles", along the lines of application/x-my-fancy-application-task-bundle, if you don't want the UA to treat it as a zip file.
Both Firefox and other browsers can decide to act on the mimetype (e.g. in Firefox's case, we show "Open in Firefox" options if you send application/pdf or SVG mimetypes, even for Content-Disposition: attachment responses, to simplify opening the content immediately). Chrome has specific checks for application/zip when sniffing.
The regressing change here was part of a fix to handling web servers who send foo.jpg files with Content-Type: image/webp, where users complained that the resulting .jpg files were not, in fact, jpegs. So we added extension normalization for a number of different mimetypes. I mistakenly assumed that application/zip files would be, you know, zip files, and could be treated as such.
You might want to report this on Mozilla's Bugzilla site (https://bugzilla.mozilla.org) under Firefox as I can't find a report that describes this exact behavior. It looks like they've broken something in the latest version (whether it was a bug or a feature is hard to say) as I noticed this behavior on a site with a mismatching Content-Type too.
Of course, if it was an intentional change, it wouldn't be the first time the Mozilla has ignored web standards to do things "their way". It still annoys me to no end that I have to use the 5-slash hack to get file protocol links to open correctly when the standards clearly state otherwise (see: https://bugzilla.mozilla.org/show_bug.cgi?id=992123)
I am using Brackets live preview to handle some old website I have. It includes links that use shtml. Note I am not using SNI capabilities on these pages. However, it looks like the content-type sent by the server, is application/shtml, instead of text/html
This forces the file to be downloaded, instead of being displayed. Is there any way to change the content-type for this file? Is there any way to configure it?
Well, I found a solution!
I go into
C:\Program Files (x86)\Brackets\www\extensions\default\StaticServer\node\node_modules\connect\node_modules\send\node_modules\mime\types
I'm editing mime.types
Search for:
text/html html htm
And change it to
text/html html htm shtml
Enjoy!
I'm targeting some SVG images with CSS to use as backgrounds on a few elements and having some strange issues. When going directly to the image it works fine, but when using in CSS I get the following error:
Resource interpreted as Image but transferred with MIME type text/xml
I've added an .htaccess file to the directory that serves the images with the following code, but it didn't help:
AddType image/svg+xml svg
Suggestions?
The probable explanation is that previously the HTTP headers specified a wrong content type, and now that you have fixed it, some software uses cached information. (Not uncommon when using XML files.) The simple way to check things out is to create a copy of the .svg file and refer to it in CSS using the new name.
When I test the URL you gave in a simple background rule, the image shows without problems on Firefox, IE, Chrome, Safari (tested on Win 7). But when I test this so that Content-Type: text/xml is sent by a server, all the browsers simply don’t show a background image; no error message is shown. So I suppose you tested with some special browser or with special settings.
Updating .htaccess did not work for me.
I added following line in /etc/mime.types and restarted apache server, cleared cache and it worked.
image/svg+xml svg
I have a webpage that is transferring A stylesheet as a text/plain MIME type. what are the possible reasons for this to occur and any tips on how to resolve that problem.
im linking the css like this
<link href="/css/app.css" rel="stylesheet" type='text/css'>
Server misconfiguration. This could depend on an overall configuration error, or on something more limited, like a badly written .htaccess file in the css directory, if the server is running Apache.
The CSS files that I am using load some images like this:
eg: main.css:
.nav{
background-image:url("/www/images/bg.png")
}
<link href="/www/css/main.css?version=1.2" type="stylesheet" />
CSS File is loaded in the HTML as shown above.
I know there is an approach that adds a query string like "?version=1.2" to force the browser to load the css file from the web server not from cache. But my problem is that this works ok for css file, but does nothing to the embedded images.
So what can I do to make the browser download the images embedded in the css or js files when I edit the images, but the names stay the same?
I would like not to:
1. change the image name
2. disable caching
thanks
May be use chrome incognito to make browser get the images every time ?
Adding a query string to the url like ?version=2 only prevents caching when the url changes every time, for instance image.png?random=123, where the value of random is different every time the page loads. The unique url forces the browser to re-fetch the image every time since the url doesn't match the url of the cached image.
Since you're wanting to use a static URL, I would suggest setting your HTTP server settings to send a header to the browser not to cache images. Let me know if you need help with that.
Can you use .htaccess file on your hosting (with mod_expires)?
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/png "access plus 1 minutes"
</IfModule>
EDIT: I saw your edit. Your question is that you want to force client to refresh images when you update them on server, without disabling browser cache?
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/png "modification plus 1 seconds"
</IfModule>
Google's mod_pagespeed plugin for apache will do auto-versioning for you. It's really slick.
http://code.google.com/speed/page-speed/docs/module.html
It parses HTML on its way out of the webserver (works with PHP, rails, python, static HTML -- anything) and rewrites links to CSS, JS, image files so they include an id code. It serves up the files at the modified URLs with a very long cache control on them. When the files change, it automatically changes the URLs so the browser has to re-fetch them. It basically just works, without any changes to your code. It'll even minify your code on the way out too.
Stolen from this post How to force browser to reload cached CSS/JS files?