My codeIgniter application serves all html pages with a header of Content type: text/html; charset=iso-8859-1. I would like it to serve utf-8 by default. I checked the config file and the database config file.
$config['charset'] = 'UTF-8';
It just keeps encoding iso-8859-1..
If you are using Apache, add this in .htaccess
AddDefaultCharset UTF-8
Make sure your HTML templates aren't setting a different charset. Check whatever templates have the opening <html> and/or <head> tags.
Edit Since your templates are encoded properly, it will probably be worthwhile to do a quick "find in files" search for iso-8859-1 and see where it's getting overridden. If it's anywhere in the core CodeIgniter instance, and you're using the most recent version (and haven't edited the core), then it might be a bug, and you'll need to report it to the CodeIgniter people.
Keep in mind, though, that it's not necessarily a bug, but a different setting overriding that one. Make sure you look at the context of any instances you find it, before you jump to the bug report form.
Related
Edit : I don't know if it actually loads from cache, so I can't create the question named "prevent from loading cache".
Problem : Browsers sometimes save my code and keep loading only the code they saved(Maybe it saves in the cache). When this problem occurs, browser is like caching the old code and won't change anything. This is to say, It won't load any new code I updated.
Information: This occurs in HTML, CSS, Javascript on all browsers. I am using Apache in XAMPP as an appserv.
Deleting cache in all browsers won't fix this.
My first way to stop this is to delete the file, refresh browser and replace it.
The second ways is changing the pathname.
After the fix, the problem will occur again at anytime :(, so I would like to know how to prevent this.
Edited: If possible, please explain for newbie because I am very young beginner.
Try adding a variable like current timestamp to each url in its query string.
Just use querystring e.g. http://www.domain.com/style.css?version=1 for first version.
Now you update the stylesheet and you would like to reflact changes to all users browser who have cached version of old stylesheet. for this just change version querystring value to 1.1
e.g. http://www.domain.com/style.css?version=1.1
This works for javascript, css and all other files called in by your html page.
Also for all files like html, css, js, you can eTag header. More information can be found here.
http://www.w3.org/2005/MWI/BPWG/techs/CachingWithETag.html
is it possible, or how could I make it so, I can include my topbar file into my page, I'd prefer it not to be with php since I am not hooked up with localhost yet.
Thanks for all help in advance!
HTML5 now allows you to include html files like you can already include a css file via an import. However, this would only be helpful for during your development stages and not for the final production version since the feature currently is only available in Chrome and will take time for the other browsers to adopt: http://www.html5rocks.com/en/tutorials/webcomponents/imports/
If you don't want to use PHP nor any other server-side scripting language,
you can use either <iframe> or <frameset> tags, which are deprecated, or perform an AJAX request using Javascript that embeds your HTML page dynamically. Second approach will work only if the page you're trying to attach is located within the same domain due to XSS protection in modern browsers.
It's more of a server thing, so to speak, so you would have to rely on the server more for this. Because, you cannot simply do this using static script, like HTML. There's no "built-in function" that can do this, it's not HTML's thing.
I mean, server will offer you more than one option, for example:
You can:
Use SSI (Server-side Includes) if server supports it.
Use PHP or ASP includes.
Otherwise, you can use AJAX for this, won't cost you as much as the above options.
If you mean "header" by saying "topbar", I think it's not a good idea to use iframes.
Files which are truly HTML parsed files can not include another file to my knowledge.
If you web server will parse php you could simply change the extension of the the main file to .php and include() the topbar file:
mv index.html index.php
index.php:
include_once("topbar.html");
Use <!--#include file="footer_text.html" -->
inside html page.
Plz, check below url for details.
https://www.lifewire.com/include-html-file-in-another-3469529
Using Google Page Speed, I get a message, "Avoid a character set in the meta tag," with a link to a page which tells me all about why I shouldn't use a meta tag to define the character set.
But my pages (WordPress) don't specify the character set in the meta tag. Instead I've done it by placing this at the top of the theme's header.php:
<?php
header('Content-Type: text/html; charset=utf-8');
?>
My questions are:
is my method of specifying the character set correct ?
if it is, why is Google's PageSpeed tool complaining about a non-existent meta tag specification ?
Check the HTML code of your page, as sent to browsers and other user agents. (E.g., use View Source when viewing the page in a browser.) The odds are that there is a meta tag that declares character encoding (“character set”). It might be generated by the authoring software you’re using.
In my tests, the only way to trigger the message when using https://developers.google.com/speed/pagespeed/ was to prevent a server from sending encoding information in HTTP and to include a meta tag for it. It is understandable in such a setting that performance may be degraded.
Otherwise, the advice from Google Page Speed in this issue is bad advice. You should declare the encoding in a meta tag in addition to declaring it in HTTP headers, as the page might be saved locally in that case, when the local copy is opened, there won’t be any HTTP headers.
I have a multi language website that is hosted on a server that appears to have character encoding set to default to iso-8859-1.
I thought I would be best having the pages utf-8 and included a meta tag to declare this. Unfortunately this meta tag seems to get overridden and the page defaults to iso-8859.
Many special characters in the German and Dutch pages are not showing correctly.
Do I need to try and change the server default to utf-8 or something? Maybe I could remove the server default completly? Hmm... really not sure what's best to do here.
Any advice would be great!
The HTML meta tags for the content type are not used when the HTML page is served over HTTP. Instead, the content type header in the HTTP response will be used. You can determine the content type header with for example Firebug, in the Net panel.
How to change this depends on the programming language and/or the webserver which you are using, which is unclear from your current question. As per you question history, you seem to be using PHP. In that case, you need to add the following line to the PHP file, before you emit any character to the response.
header('Content-Type: text/html; charset=UTF-8');
See also:
PHP UTF-8 cheatsheet
If you're unable to change the HTTP response header, you have to give more detail about the programming language and webserver which you're using. This way we can give you better suited answers.
If you want to stick to ISO-8859-1, then you need to ensure that your pages are saved as ISO-8859-1 as well instead of as UTF-8. Otherwise some characters may indeed go mojibake when you display a UTF-8 saved resource as ISO-8859-1.
There are several possible solutions, but the cleanest solution would be to properly declare your character encoding.
When serving web pages from an HTTP server, the encoding is normally not given by the meta-tags of the HTML file, but by the Content-type HTTP header.
The webserver is probably sending something like Content-type: text/html; charset=ISO-8859-1, and you need to change that.
How to do this depends on the webserver.
As an addition: Yes, iso-8859-1 is fine for German; it will work for all western European languages. It is missing a few characters, however, notably the Euro sign (that is in iso-8859-15). But using UTF-8 is better, as it covers just about every language.
You can see the characters supported and the languages that should cover in this Wikipedia article. According to that, German is fully supported and Dutch is almost.
It's not just a matter of selecting the correct character encoding, you also have to save the pages using that encoding. If you save a page as ISO-8859-1 and use a content type that says that it's UTF-8, then it will be decoded incorrectly by the browser. Both ISO-8859-1 and Unicode support the characters you need, but you have to make sure that the content type corresponds to how the pages are actually saved.
I'm treating all *.jpg files as static, but I need to serve a few dynamically. Can I simply omit the extension so I don't have to get fancy with my url rules? Is it enough to just set the file type in the header?
I've never had a problem serving dynamic images with a strange extension or no extension at all. Querystrings are also fine.
It will be enough for the headers to be correct and the binary file correctly formed. When you do this make sure you also set the Content-Disposition to a reasonable file name so people don't try to download your files with crazy querystring names. (Which windows users will be unable to save since they will most likely have a "?" in them.)
Instead of omitting the extension (on your server), activate content negotiation (i.e. +MultiViews if you're using Apache) and omit the extensions in your URIs. That way, Apache will decide what file to serve; you could have an image in both png and svg format, and serve the one accepted by the browser.
Generally, a correct Content-type header is enough.