locked
Using localized resources in external Javascript files RRS feed

  • Question

  • User1738843376 posted

    Hi,

    I have been developing sites with a lot of JavaScript/JQuery code on my webforms websites, and i end up, quite frequently, with more than 1000 lines of JS code.

    I want to externalize this code, to keep the page more manageable, but a lot of this JS has text that is filled from Resources (RESx files) according to the localization.

    I know i could build an array at the top of the JS code with all the resources that might be called and externalize the rest of the JS, calling from within the externalized JS functions the values from the array that would have already been loaded to the page before the external JS that uses them is called, but i'm not sure if this the best approach to this situation... 

    Any different ideas or insights regarding this 'issue' would be appreciated,

    Thanks

    Friday, February 14, 2020 2:58 AM

All replies

  • User-474980206 posted

    There are several popular JavaScript internationalization libraries. Google for options. 

    Saturday, February 15, 2020 12:53 AM
  • User288213138 posted

    Hi 0belix,

    I have been developing sites with a lot of JavaScript/JQuery code on my webforms websites, and i end up, quite frequently, with more than 1000 lines of JS code.

    I want to externalize this code, to keep the page more manageable, but a lot of this JS has text that is filled from Resources (RESx files) according to the localization.

    I know i could build an array at the top of the JS code with all the resources that might be called and externalize the rest of the JS, calling from within the externalized JS functions the values from the array that would have already been loaded to the page before the external JS that uses them is called, but i'm not sure if this the best approach to this situation

    I think the the best approach is use a Localization Handler to serve ASP.NET Resources to JavaScript.

    You can try to create a custom HttpHandler that can serve server side resources as client side resource objects to a JavaScript page.

    More information about how to create an ASP.NET JavaScriptResourceHandler HttpHandler you can refer to this link:

    https://weblog.west-wind.com/posts/2009/Apr/02/A-Localization-Handler-to-serve-ASPNET-Resources-to-JavaScript

    Best regards.

    Sam

    Monday, February 17, 2020 3:50 AM