Can't import less files encoded in UTF-8 BOM - javascript

I use the less compiler with node.js and I know there is an issue with the files encoded in UTF-8 with BOM. For this, this workaround works great:
data = data.replace(/^\uFEFF/, ''); // Strip potential BOM
However, when importing files, using #import statements still gives a syntax error on first line. Are there any way to work around this as well?

The BOM will be stripped in the next version of less.js - 1.3.1. You can also try it out on the github source pages.
https://github.com/cloudhead/less.js/commit/6696368eb351824f33dc0aac67143d8ea80a085a

A BOM in an UTF-8 file makes no sense.
You should fix the source files as many other tools will (rightly) have problems with this BOM. All serious editors are able to write UTF-8 files without BOM.
If you must receive and handle such files, you should automaticaly fix them using for example (operating on a work copy if needed) :
awk '{if(NR==1)sub(/^\xef\xbb\xbf/,"");print}' INFILE > OUTFILE
(taken from Using awk to remove the Byte-order mark)

Related

How to correctly include a javascript file into html

I am trying to run a script through HTML but I am having some problems. I searched online and found how to do so, however the issue is that even if I correctly type the path of the .js file, it seems to add some strange characters before it.
This is in index.html
<script type="text/javascript" src="fractalTest/fractalTest.js"></script>
I expected this to work but when I open index.html in google chrome and inspect then look under the elements tab, this "â©fractalTest/fractalTest.js" is replacing "fractalTest/fractalTest.js" in the path of the file. I believe this is whats causing the error but I do not know how to fix it!
...it seems to add some strange characters before it.
That usually means that the file is saved with a byte-order mark (BOM) of some kind, but isn't being sent with the correct charset for that byte-order mark.
Be sure that the server is configured to serve the files with a specific encoding (UTF-8 is a good choice), and that you save the files using that encoding (in your text editor, etc.). It's also usually best not to include a BOM on UTF-8 files (although it's valid, some tools don't handle it well).
Side note: No need for the type attribute. The default is JavaScript.

Making JettyRunner serve up static content (like CSS and JavaScript) with UTF-8 encoding

I'm running a Java project via Jetty Runner (7.6.15). I've been trying to play with D3.js lately, and I needed to serve it up unminified in order to debug some mystery problem. Well, D3 has some non-Latin Unicode characters in some variable names (like var π = Math.PI).
When I try to use that unminified file, I get errors because my browser thinks the character encoding is ISO-8859-1 instead of UTF-8. Sure enough, the "Content-Type" header in the server response has no character set.
I'm launching Jetty Runner with LANG and LC_ALL both set to "en_US.UTF-8", and I'm passing a system property file.encoding set to "UTF-8" as well on the Java command line. That apparently is not enough. I can look at the source file on my host and it's definitely intact; in fact if I load the JavaScript file directly from the browser address bar and manually tell Firefox that it's Unicode, then it looks fine.
I'm not launching Jetty Runner with a configuration file because I have no idea how to do that. It seems to add an explicit ISO-8859-1 marker to the content type header on the main HTML page (it's a single-page application), and that of course overrides the <meta charset> tag in the document head.
So is there a way to do this? Sometimes I feel like I'm one of the only 12 people on earth who use Jetty Runner :)
This turned out to be as simple as a clause in my web.xml:
<mime-mapping>
<extension>js</extension>
<mime-type>application/javascript; charset=UTF-8</mime-type>
</mime-mapping>
I don't know how something this obvious escaped my notice. It doesn't even have much to do with Jetty per se.

All my css and js does not work if there is even a single line of code written in the .htaccess file, how to fix it?

All my css and js external files does not work (they are not read or they are read wrongly by the browser) if there is even a single line of code written in the .htaccess file, how to fix it? Is there some kind of config that erases all previous mimes if I write a line in .htaccess?
Details:
Server:Apache
Mimes working: All html, htm and php files work.
Failing mimes so far: css and js. They are currently being loaded as php files with forced headings.
Text in .htaccess: Its nothing specific that i need to write on the htaccess, any single line of any code makes the css and js fails. (Example of single line code: "ServerSignature Off")
If that line happens to be RewriteURL for a minify script for instance, that doesn't send the proper Content-Type headers, then yes, it just might :D

Funny characters in my javascript file

This character () gets added to my javascript file. i am using visual studio 2010.
has any one come accross this issue?
This link explains my problem and a solution
http://forums.silverlight.net/t/144306.aspx
Cheers
The js file is encoded as UTF-8 and has a byte order mark (BOM) identifying it as such.
This shouldn't be a problem so long as you serve the file up as UTF-8.
If the page doesn't already use a meta tag with the content type set to UTF-8, you can add this information to the script element, as described here:
<script src="js.js" type="text/javascript" charset="utf-8"></script>
The characters added are BOM characters,are not advised for utf-8. Visual studio by default saves javascript files with "Unicode(UTF-8 with signature)- Codepage 65001" encoding, this encoding adds the UTF-8 byte order mark at the beginning of the file. ie9 and chrome do not have a problem with it but firefox, opera and safari completely break....
so to fix it follow the solution in this document
http://forums.silverlight.net/t/144306.aspx and select the encoding option "Unicode(UTF-8 without signature)- Codepage 65001".
Hope this Helps.
Cheers

Problem with special characters when Minifying JS

I'm using MVC ScriptManager to Compress and concatenate all my .js files. It works very well, except that if a *.js has a special character such as "á, à" it turns to "Ã!".
I'm trying to change the source code but with no success so far.
Does anyone have an idea what this could be?
Thanks!!
You can write them like \u00f1. Here you can look up the special characters: http://www.fileformat.info/info/unicode/char/search.htm
It looks like the source file encoding is ANSI, and the output is encoded as UTF-8.
In VS use the Advanced Save Options from the File menu to save the original .js file as UTF-8 with a signature (code page 65001).
I make a point of saving all text-type files (.cs, .js, .css, etc.) as UTF-8 to avoid any of these issues later on.

Categories