Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set charset to .js file in MVC ScriptBundle?

I have script.js file that contains several string in cyrillic. When i attempt to load this with standart link like this:

 <script type="text/javascript" src="~/Content/Script/Script.js"></script>

cyrillic letters become rectangulars/badCharsetCaracters.

This solves the broblem:

<script type="text/javascript" src="~/Content/Script/Script.js" charset="windows-1251"></script>

How can I set charset with ASP.NET MVC 4 Bundles? Code like this:

 bundles.Add(new ScriptBundle("~/bundles/scripts").Include(
                     "~/Content/Script/Script.js"));
like image 827
Barada Avatar asked Apr 26 '13 09:04

Barada


2 Answers

You can use the Scripts.RenderFormat to specify your custom script tag rendering format:

@Scripts.RenderFormat(
    "<script type=\"text/javascript\" src=\"{0}\" charset=\"windows-1251\"></script>", 
    "~/bundles/scripts")
like image 190
nemesv Avatar answered Sep 22 '22 01:09

nemesv


Change your script file's encoding to your website's encoding.

For example, if your site is encoded in UTF-8, then:

  1. Open your script file in the windows' notepad
  2. Click File > Save as
  3. Change encoding to UTF-8 (list of encodings is in front od the "Save" button)
like image 41
cryss Avatar answered Sep 18 '22 01:09

cryss