Git Product home page Git Product logo

Comments (7)

jimitndiaye avatar jimitndiaye commented on July 20, 2024

Also looking at the source of angular-rendering.js there doesn't seem to be support for using preboot, i.e renderToStringWithPreboot rather than renderToString.

from javascriptservices.

SteveSandersonMS avatar SteveSandersonMS commented on July 20, 2024

That's correct - thanks for bringing up these points.

If you have any time to work on adding this functionality I'd be pleased to take a pull request. Otherwise I'll aim to get to it at some point, though there are lots of other jobs higher up on my list so there's no ETA.

from javascriptservices.

jimitndiaye avatar jimitndiaye commented on July 20, 2024

I'll take a stab at adding preboot support. That should be relatively straight forward. Workers might be slightly trickier but I have some ideas.

from javascriptservices.

jimitndiaye avatar jimitndiaye commented on July 20, 2024

I've got preboot mostly working. However I notice that in the angular2spa template you're requiring the client code to do the server side render. If that's the model you're going for then it makes more sense for the other of the client code to be responsible. That way AngularServices doesn't have to be changed every time angular2 changes.

In any case I changed renderToString as follows:

    renderToString: function(callback, options) {
        try {
            var component = findAngularComponent(options);
            var serverBindings = [
                ngRouter.ROUTER_BINDINGS,
                ngUniversal.HTTP_PROVIDERS,
                // TODO: BASE_URL has been replaced by REQUEST_URL in [email protected]
                ngCore.provide(ngUniversal.BASE_URL, { useValue: options.requestUrl }), 
                ngCore.provide(ngRouter.APP_BASE_HREF, { useValue: '/' }),
                ngUniversal.SERVER_LOCATION_PROVIDERS
            ];

            return (options.preboot
                ? ngUniversalRender.renderToStringWithPreboot(component, serverBindings, {
                   freeze: { name: 'spinner' },
                    replay: 'rerender',
                    buffer: true,
                    debug: true,
                    uglify: false,
                })
                : ngUniversalRender.renderToString(component, serverBindings)).then(
                function(successValue) { callback(null, successValue); },
                function(errorValue) { callback(errorValue); }
            );
        } catch (synchronousException) {
            callback(synchronousException);
        }
    }

As you can see not much needs to change to support preboot. In your Angular2Spa template, for instance, just call ngUniversalRender.renderToStringWithPreboot as illustrated above.

In any case I can create PR for the renderToString change (and associated taghelper attribute to enable preboot) or you could opt for the option currently illustrated in the template Angular2Spa template where each framework provides their own prerender code. I like the latter as it makes implementing web workers much easier.

from javascriptservices.

SteveSandersonMS avatar SteveSandersonMS commented on July 20, 2024

Thanks for looking into this.

or you could opt for the option currently illustrated in the template Angular2Spa template where each framework provides their own prerender code. I like the latter as it makes implementing web workers much easier.

Yes, I agree, and that is the model I'm leaning towards. I'll remove the older asp-ng2-prerender-module tag helper in favour of the newer and more flexible asp-prerender-module one soon.

So I guess, as per your research, there isn't much we need to do here, as the developer can control their use of preboot by editing the boot-server.ts file in whatever way they want.

If you get any insight into what we should do for web workers (if anything) please let me know.

from javascriptservices.

jimitndiaye avatar jimitndiaye commented on July 20, 2024

Yea the asp-prerender-module option is much more flexible. Preboot works with zero modification, though I did modify the asp-ng2-prerender-module to support preboot anyway.

For workers, as it turns out there isn't much to do there either. You go from having one entry file to multiple (one for the UI thread and the other for the web worker which is loaded asynchoronously). Pre-rendering works as it does now and I was able to get that working.

The only thing I had problems with was using the webpack dev server as there wasn't an obvious way of setting the path to the webpack.config.js file like you can do when setting up the prerendering tag helper. Could just be user error on my part.

To demonstrate web worker support in the template you could do something like i've done here (though mine's not finished due to time constraints but the basic idea is there.

In terms of tooling to support web workers, the only thing I can think of is item templates in VS for bootstrap files.

Slightly off-topic, I was watching your NodeServices presentation at NgConf, I think, in London. Was very well done.

from javascriptservices.

SteveSandersonMS avatar SteveSandersonMS commented on July 20, 2024

I'm just tidying up some issues and it looks like it would be reasonable to close this one, unless anyone has any specific objections.

The preboot issue is resolved since we migrated to the asp-prerender-module helper (you can just pass preboot: true).

About web workers, this is also now entirely under the control of the developer since the asp-prerender-module approach lets you implement whatever server-side boot code you want. We probably won't use web workers in the default Angular2Spa template because it would increase complexity and make it hard to understand for newcomers. Or if anyone thinks it's really important and can be done simply please let me know.

from javascriptservices.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.