locked
Best practices for loading resources from a js custom control

    Question

  • Hello, I built a custom control for html/js that I distribute using a .vsix file. Developers using my component will just add references to my component and link the .js and .css files via script and link tags in their code (identical to how a developer would add WinJS to their project). I have everything working except I don't know what the best practice is to allow my component to load localizable resources (included in .resjson file) that is distributed with my component.

    What I have working: I require the developer to add my .resjson file to their project.

    However, this is a somewhat cumbersome step and ideally I'd like to see my component somehow automatically load their own .resjson files without the consumer of my component having to do anything extra. I've tried to figure out how WinJS loads base.strings.js and ui.strings.js and tried using a similar naming convention for my own files but haven't been able to figure out how to get this to work.

    What is the recommended practice for creating redistributable js components that have their own localized resource files?

    Thanks,

    Tim

    Monday, March 05, 2012 6:50 PM

Answers

  • Hi Tim,

    Assuming you are using Visual Studio to build your custom js control, you should see a *.pri file in the build output location. That pri file contains the index of the localized resources in your controls. If you include this pri file appropriately in the .vsix file, when other people consumes the component, they'll install the .vsix and the pri file will get laid down on their machine in the appropriate place. Then when they build their project, the pri file for your control will get merged appropriately with the final pri file of their app so that all resources are merged into a single pri file to be loaded at runtime.

    Does this help?

    Tuesday, March 06, 2012 2:08 AM

All replies

  • Hi Tim,

    Assuming you are using Visual Studio to build your custom js control, you should see a *.pri file in the build output location. That pri file contains the index of the localized resources in your controls. If you include this pri file appropriately in the .vsix file, when other people consumes the component, they'll install the .vsix and the pri file will get laid down on their machine in the appropriate place. Then when they build their project, the pri file for your control will get merged appropriately with the final pri file of their app so that all resources are merged into a single pri file to be loaded at runtime.

    Does this help?

    Tuesday, March 06, 2012 2:08 AM
  • Thanks Candy, that makes sense. What kind of project is the best type for a redistributable js custom control? I don't see a js class library but it seems like I could either create a js app or a c# winmd project with a dummy class.

    Regards, Tim

    Tuesday, March 06, 2012 2:40 AM
  • Yep. Either one of those works. A C++ winmd project would work as well.
    Tuesday, March 06, 2012 6:45 PM