This project is read-only.

Load orchard custom widget asynchronously

Topics: Administration, Core, Customizing Orchard, General, Installing Orchard, Writing modules, Русский (Russian)
Nov 25, 2014 at 1:18 PM
Hi All,

I have written custom module using some examples. I'm using ContentPartDriver inherited class to render results...

for example:
        protected override DriverResult Display(ContentPickerPart part, string displayType, dynamic shapeHelper) {
        string IWSUrl = IWSUrlRuleProvider.BuildIWSUrl(part);
        var lstTypeItems = _contentpicker.GetItems(IWSUrl);

        return ContentShape("Parts_ContentPicker", () => shapeHelper.Parts_ContentPicker(
                    Items: (lstTypeItems as List<Item>)));
Module is requesting web service to get some information... As there is a lot info it takes about 400ms to just call web service... I have about 10 same modules per page and it takes 400*10 secs to render...

How can i render this module asynchronously in orchard cms?(So page will be rendered and after there will be ajax calls for each modules)

Nov 25, 2014 at 3:36 PM
You could use the Ajax Widget module to load your widgets via AJAX, separately from the page request: BTW of course you can roll out your own async client-side implementation, where the widget just renders some HTML and JS that in turn loads the actual data by fetching it through an ApiController.

Any way, with such slow external APIs I'd also think about caching (preferably Orchard.Caching) and parallelisation (in requests, as opposed to background tasks, you can freely use async/await as well, it will work inside Orchard; however due to async's cascading effect you can't really do this from drivers).