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

I have a script.js file that contains several lines in cyrillic. When I try to load this with a standard link, for example:

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

Cyrillic letters become rectangular / badCharsetCaracters.

This solves the problem:

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

How to set encoding using ASP.NET MVC 4 packages? Code like this:

 bundles.Add(new ScriptBundle("~/bundles/scripts").Include(
                     "~/Content/Script/Script.js"));
+5
source share
2 answers

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

@Scripts.RenderFormat(
    "<script type=\"text/javascript\" src=\"{0}\" charset=\"windows-1251\"></script>", 
    "~/bundles/scripts")
+10
source

Change the encoding of your script file to the encoding of your site.

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

  • Open a script file in windows notepad
  • "" > " "
  • UTF-8 ( "" )
+2

All Articles