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,
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:
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Participant
1226 Points
857 Posts
Using localized resources in external Javascript files
Feb 14, 2020 02:58 AM|0belix|LINK
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
All-Star
58124 Points
15635 Posts
Re: Using localized resources in external Javascript files
Feb 15, 2020 12:53 AM|bruce (sqlwork.com)|LINK
There are several popular JavaScript internationalization libraries. Google for options.
Contributor
3370 Points
1409 Posts
Re: Using localized resources in external Javascript files
Feb 17, 2020 03:50 AM|samwu|LINK
Hi 0belix,
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