Single wohnung recklinghausen nord

single page applications in asp.net mvc 4

frau will sich nicht mehr treffen

This site uses cookies for analytics, personalized content and ads. By continuing to beim kennenlernen rar machen browse this site, you agree to this use.

Play Building Single Page Apps for desktop, mobile and tablet with ASP.NET MVC 4

01:13:43

Description

So you want to build a highly-responsive, native-like application that runs in a regular browser, and a mobile touch device browser, and in some cases can even be packaged and sold on a mobile app store? And you want to do it using only familiar web development technologies, including ASP.NET MVC 4 and JavaScript? In this session, Steve will demonstrate how modern Single Page Application (SPA) architecture combines the best bits of web-like and desktop-like user experience, applying libraries such as Knockout.js and Upshot.js to streamline the development process.
For more information, check out these courses on Microsoft Virtual Academy:

Tag:

Day:

Level:

Code:

2159

Share

Embed

Download

Download this episode

For more information, check out these courses on Microsoft Virtual Academy:

The Discussion

  • User profile image erik_

    Great session!

    Would love to see the sample code, because it looks like upshot.js is kinda undocumented at the moment.

    Where do we find the html helper for mvc?

    Last modified

  • User profile image ronaldh

    For me this was beim kennenlernen rar machen the best session at techdays.

    I'd like to be able to download the sample code as well (couldn't find it at Steven's blog)

    Last modified

  • User profile image williamve

    Last modified

  • User profile image Flynn0r

    Very awesome presentation.

    Last modified

  • User profile image Steve Sanderson

    Downloadable code coming soon!

    Please bear with us for a few days as we're working furiously to get an Upshot/SPA update out via NuGet. As soon as that is done, I'll be able to post a link to the DeliveryTracker sample and it will work on your beim kennenlernen rar machen machines too :)

    We're also setting up an Upshot/SPA website where we'll put more docs and samples.

    Thanks for the positive comments BTW :)

    Last modified

  • User profile image Brianweet

    Thanks Steve, awesome presentation at techdays!

    Waiting for the code sample Smiley

    Last modified

  • User profile image Johan Dorssers

    From the first till the last word I was focussed. No minute spoiled.
    Thank you very much Steve it was realy helpfull.
    Can't decide which presentation was better tho...this one or 'C#5, ASP.NET MVC 4, and asynchronous Web applications' :)
    BTW, when does this vid come up on channel 9 Steve...
    Looking forward for the code sample

    Last modified

  • User profile image JanAB

    Awesome presentation material :-D
    Btw, what's the name of the source control system Steve is using?

    Last modified

  • User profile image Knut Marius

    Awesome presentation!

    JanAB, He was using Mercurial: http://mercurial.selenic.com/

    Last modified

  • User profile image Eugene

    Indeed an awesome presentation! I was wondering, what tool or feature did you use to copy your code snippets during your presentation?

    Last modified

  • User profile image Tugberk

    Steve,

    You and Scott Hanselman are two of the best speakers I have ever listened. Very nice session and every second of it was worth watching. Thanks!

    Last modified

  • User profile image BertVan​Kammen

    This was a great session.

    Flawless presentation and good speed discussing topics. Got me on the edge of my seat.

     

    Last modified

  • User profile image Eugene

    I just found out that you can drag code in the toolbar... :)

    Last modified

  • User profile image Egbert Nierop

    If you run Install-Package Upshot
    it delivers you knockout.js etc. but the sample that Steve runs, e.g. returns XML as a format, instead of Json. So, it looks like something seriously has changed in the current MVC runtime.

    Last modified

  • User profile image WdK

    Nice presentation! 

    When switching to Mobile, Steve hits a button in his browser that switches to iPhone. Is that a plugin in or something? 

    I also have to say, that although I really like the speed and simplicity of building a mobile App this way I'm a little bit of afraid of testing such an app when it gets bigger. There is almost no server code so things like Unit Testing will be hard. Can we use some javascript unit testing framework for this? 

    Thanks!

    Last modified

  • User profile image Stuart

    This presentation has me excited about web dev again, this is some top notch tooling to get us writing some really cool stuff. All presenters for MS should be British from now on, except ScottGu and Hanselman ;-)

    Last modified

  • User profile image BrianJimdar

    Oh man Steve! This is so beautiful. 

    Silverlight was great, but is probably over for must of *my* future projects. Html/Javascript seemed like such a mess. I feel like you just showed us the way forward. At one point in the presentation I discovered. I was weeping for joy. Windows web programming is back on the map.

    @WdK: No problem, start here:  

    Last modified

  • User profile image Vin

    Steve,

    An incredible presentation, covering a variety of important topics, clear instructions, smooth flow and a great looking demo app at the end. After knockout, now I am digging upshot.js.

    Thanks a ton!
    Waiting for the sample code,
    Vin @vinayakkamat

    Last modified

  • User profile image benjoyce

    Does anyone know how Steve seeded his data in the demo?  It was hidden from view (at position 18m15s).

    Last modified

  • User profile image Irfan Shaikh

    Lots of Data access features shown are already in the Silverlight Rich Internet application (RIA), which I felt is very easier than SPA. If Microsoft put some efforts on releasing Silverlight plug-in for Android and iOS and some new Mobile Industry features like app store, local storage. Actually make development very easy.

    But I must say awesome presentation by Steve.

    Thanks,
    -IS

    Last modified

  • User profile image Deactivated User

    Comment removed at user's request.

    Last modified

  • User profile image Arthur

    Hi,
    Could anybody help me find which extension is for Chrome is used in this presentation to emulate other browsers at 47:57?
    This looks like a very useful feature.

    Thank you

    Last modified

  • User profile image mjepson

    When / where will the sample code used in this presentation be released?

    Last modified

  • User profile image ozhug

    thanks steve frau will sich nicht mehr treffen great presentation

    Last modified

  • User profile image mjepson

    After I add the TasksController, I get problems involving my connection to my SQL server. We have a development SQL server here, and I have updated the connectionstring in the web.config.

    Now how do I get it to create my database? In the demo it seems the database is magically created somehow, but when I run my solution and navigate to /tasks, I get an exception:

    A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)


    In my code I also get a debugger breaking on the javascript line:

     upshot.metadata(@(Html.Metadata<MvcApplication1.Controllers.MvcApplication1Controller>())); 

    Any help is much appreciated!

    Last modified

  • User profile image delaci

    This is one of the best sessions I've watched. Was impressed by the other presentation of Steve's regarding knockout.js. Got excited when I saw ScottGu's presentation on Mvc 4. This is the icing on the cake. Very powerful stuff and very well presented.

    Last modified

  • User profile image box101

    @Steve: Any update about the used source code in the TechDays presentation?
    It was an awesome presentation with a nice demo app indeed and I just want to go through it again.

    Last modified

  • User profile image Jaikishan Jalan

    Super cool video. Feels like lot to learn with so many new libraries.

    Last modified

  • User profile image stevepresley

    @: I'm pretty sure it is "User-Agent Switcher for Chrome", it looks very similar to the one he demoed this week at the MVP Summit.

    Last modified

  • User profile image Steve Sanderson

    The source code for the DeliveryTracker app is now available - for details, see http://blog.stevensanderson.com/2012/03/06/single-page-application-packages-and-samples

    Last modified

  • User profile image Sagy

    @:If you haven't resolved it yet...

    It seems EF + CF are ignoring te connections string inside web.config and are using SQL Express by default, unless specified otherwise, so... specify otherwise:

    Inside the context class (where you would normally have all the DbSet<EntityName>) add a constructor with a line similar to this:

    this.Database.Connection.ConnectionString = "Data Source=localhost;Initial Catalog=name-of-your-db;Integrated Security=true";

    Hope it helps - it took me a couple of hours to solve it.

     

     

    Generic Comment Image

    Last modified

  • User profile image johnstaveley

    superb and inspirational! Well done, this is where I'd like to take my development in the next few years!

    Last modified

  • User profile image Dilish Velayudhan

    Awesome Steve..! Became a fan after reading your books, you showed how validation needs to be implemented by creating a validation framework (MVC 1.0) and got adapted by later MVC frameworks, then Knock out, now SPA
    Really feel proud to be a Microsoft Web Developer..
    Gr8..!!

    Last modified

  • User profile image StefH

    Hi Steve,

    It seems that the DbDataController only supports EntityFrameWork entities, this means that my model entities should be real Entities.

    It's not possible to use ViewModels anymore. So my question is : what's the design concerning ViewModels when using this new Upshot.js to access the DbDataController?

    I've also posted a question on, maybe you can take a look and shed some light on this issue.

    Thanks!

     

     

    Last modified

  • User profile image Adam Downs

    Hello Steve,

    Is there a release date planned for the offline data stores?

    Also is there any documentation available for Upshot?

    Last modified

  • User profile image Qorbani

    AWESOME! Thanks Steve for this great session. 

    Last modified

  • User profile image Patrick MA

    I've been waiting for something like this, absolutely awesome. Steve Sanderson is a legend! :)

    Last modified

  • User profile image Carlos

    AMAZING session, best one I've seen in years. Incredibly accurate, well prepared and explained. I had to replay your "generic touching device" joke a few times. ;)

    Besides, the technology presented is brilliant too!

    Last modified

  • User profile image mrrdr

    Great Video. Super fast explanation of so many different items in such a short time, seems like the video is only 5 minutes long. I take it as a reference now for every project I start using the same set of techniques. Definitely a reference for client side apps even if the back end is not Microsoft based. Steve, we all Microsoft developers have to appreciate your geniality.

    Last modified

  • User profile image Stephen

    Thanks for making the source code available.

    Last modified

  • User profile image Stephen

    Thanks for this. It works great. Unfortunately, the first modification I made was to add a date field to the model. This causes the entire project to come to a crashing halt because of what appears to be a conflict between the json.net and upshot.js libraries. Any idea on when this will be fixed or when a workaround will be available? Thanks.

    Last modified

  • User profile image John Billingsly

    Hi Stephen,, how are Single Page Apps and WCF RIA Services and the support it is creating for non-Silverlight client with RIA/JS related?

    Thanks,

    Last modified

  • User profile image John Billinglsly

    Sorry, meant Steve above...

    Last modified

  • User profile image Pitts

    excellent presentation.... 

    Thanks

    Last modified

  • User profile image Paulo Ortins

    Awesome Steve, i will start a project now!

    Last modified

  • User profile image HockeyJ

    Brilliant technology, excellently presented. Nice work.

    Last modified

  • User profile image Aleksandar

    Please if anyone know which Google chrome extension is use for mobile phone emulating in this awesome video.

    Last modified

  • User profile image Tahr

    Good to see Microsoft working in this direction.

    Last modified

  • User profile image DL123

    Can someone clarify Steve mentions that you can install SPA using phonegap to a mobile phone. However, I see that SPA can be built with either static html pages or views or both. It is true that we can only install the static html pages and not the views? will phonegap acceot views? Thanks

    Last modified

  • User profile image dl123

    Can someone clarify Steve mentions that you can install SPA using phonegap to a mobile phone. However, I see that SPA can be built with either static html pages or views or both. It is true that we can only install the static html pages and not the views? will phonegap acceot views? Thanks

    Last modified

  • User profile image mj0624

    I do not see why anyone thinks this is great. It is a return to notepad development! I would never want a piece of java script acting as a view model, there was not a single bit of intellisense confirming that the object model is correctly bound, and the UI is directly bound to the implementation of the database. This isn't a return to "great web development" but a return to the horrid web development prior to WCF, XAML, and true MVVM implementations with C# classes behind the UI.

    Last modified

  • User profile image Hakan

    Awesome presentation, one of the best I've ever seen.
    Where do we set WebApi url in upshot. We set datasource here:
    @(Html.UpshotContext(bufferChanges: true).DataSource<DataServiceController>(x => x.GetDeliveriesForToday()))

    But, no idea how to set source url for different environment?

    Last modified

  • User profile image AlexSkachkov

    @:

    PhoneGap use WebView/UIWebView of Android/iOS for render page. WebView in PhoneGap can work only with html pages which are packed to the app. 

    Last modified

  • User profile image statichtmla​ndstoredpro​cs

    I've been using static HTML with JQuery and stored procs for years. All you need to do is pass XML through a.ashx file to a database, get back a Dataset as a JSON object. It only takes about 100 lines of C# code, the rest is Javascript on the front and SQL on the back. You don't need EF, ORM, LINQ, or anything else in the middle if you know how to pass XML/JSON, and put business rules in stored procs...SQL developers love it, those with little or no SQL skills hate it and prefer to put all of their code in big middle tiers that won't work on mobile devices like PhoneGap. You don't need MVC once you know Javascript UI development, which you have to know in order to develop for mobile devices anyway. C#/Java/PHP UI code will soon be a thing of the past, I predict.

    Last modified

  • User profile image DangerMoose

    Warning: This video will get you very excited, you may think yes this is how will write my next online/offline mobile app.

    If you do then prepare to cry, as you will then boot up VS2012 and find that the SPA project template has been removed. Oh Microsoft you do like to torture us poor devs.

    Can anyone give me some pointers to another tutorial which shows a way to achive the same results without using the SPA template?

    Thanks

    Last modified

  • User profile image Belkin

    @: well SPA its not some thing what you can not use without template. 

    Go ahead install upshot.js from NUget, install knockout and start with your application.

    Also if you watch presentation he mentions that its SPA is part of Asp.net MVC 4 did you installed it?

    Last modified

  • User profile image DangerMoose

    Thanks @Belkin, I will start learning upshot & knockout and hope the SPA template returns soon.

    Yes I have MVC 4 as that came with VS2012

    Last modified

  • User profile image Oran

    Hi Steve,

    Thanks for the presentation. Really exciting stuff

    I'm currently designing a new application using EF but I have an extra abstraction layer above the EF code (to cater for more complex database scenarios other than simple CRUD) which means that the layer exposed to my web api isn't a DataController but just a normal class library.

    Is there any way to get upshot work in this case or do I have to get rid of this extra layer of abstraction?

    Thanks
    Oran

    Last modified

  • User profile image Preilly

    Hi would love to build this app but do not have sql express, will it work with sql server 2008??
    Thanks for help!!

    Last modified

  • User profile image JulioNobre

    Hi Steve!

    Just to let you know that I think this indeed a dense and, most of all, awesome presentation.

    You really did a great job. Well done. Smiley

     

     

     

    Last modified

  • User profile image Ravindar Reddy

    awesome presentation.

    Last modified

  • User profile image Srini

    In VS 2012 SPA is under Visual F# | ASPNET with the name "F# and C# Web Application (ASP.NET MVC 4)". Or click online tab and search for SPA/Single page.

    Last modified

  • User profile image val

    Great presentation! It was clear and to the point. However, I've had no success (after over a week of failed attempts) with getting this up and running. The VS2010/Nugget setup is BUGGY AS HELL! There is no greater let down than getting amazed by sweet ASP.NET/MVC4/HTML5/Offline goodness only to realize later on that IT'S NOT READY YET!

    Last modified

  • User profile image Gaja Kannan

    Such a shame!!!  Channel9 videos don't run on Windows RT/Surface RT.  I am getting an message that it requires Silverlight installed because browser doesn't support h264 mp4 html5 natively.  Come on guys really!!!

    Last modified

  • User profile image gduncan411

    @:Check your Format, you might be forcing Silverlight (aka smooth andor progressive), click on the "Format" button under the video to see.

    Set it to auto or HTML5 and try again. The videos work fine in Surface RT (and IE on Xbox, etc)

    Last modified

  • User profile image Tarabass

    @SteveThank you for pointing me this way. Love the approach to create webapplications this way. I'm always looking forward to see your sessions!

    @Sagy

    You are my hero too! Creating the constructor with the connection string solved my problems!

    Last modified

A single-page application (SPA) is a or that interacts with the user by dynamically rewriting the current page rather than loading entire new pages from a server. This approach avoids interruption of the between successive pages, making the application behave more like a. In an SPA, either all necessary code –,, and – is retrieved with a single page load, or the appropriate resources are and added to the page as necessary, usually in response to user actions. The page does not reload at any point in the process, nor does control transfer to another page, although the or the can be used to provide the perception and navigability of separate logical pages in the application. Interaction with the single page application often involves dynamic communication with the behind the scenes.

Contents

History[]

The origins of the term single-page application are unclear, though the concept was discussed at least as early as 2003. wrote the Self-Contained website at slashdotslash.com with the same goals and functions in April 2002 and later the same year, Lucas Birdeau, Kevin Hakman, Michael Peachey and Evan Yeh described a single page application implementation in the US patent 8,136,109.

JavaScript can be used in a web browser to display the (UI), run application logic, and communicate with a web server. Mature open-source libraries are available that support the building of an SPA, reducing the amount of JavaScript code the developer has to write.

Technical approaches[]

There are various techniques available that enable the browser to retain a single page even when the application requires server communication.

JavaScript frameworks[]

Web browser JavaScript frameworks, such as,,, and have adopted SPA principles.

  • is a fully client-side framework. AngularJS's templating is based on bidirectional. Data-binding is an automatic way of updating the view whenever the model changes, as well as updating the model whenever the view changes. The HTML template is compiled in the browser. The compilation step creates pure HTML, which the browser re-renders into the live view. The step is repeated for subsequent page views. In traditional server-side HTML programming, concepts such as controller and model interact within a server process to produce new HTML views. In the AngularJS framework, the controller and model states are maintained within the client browser. Therefore, new pages are capable of being generated without any interaction with a server.
  • is a client-side JavaScript web application framework based on the model-view-controller (MVC) software architectural pattern. It allows developers to create scalable single-page applications by incorporating common idioms and best practices into a framework that provides a rich object model, declarative two-way data binding, computed properties, automatically-updating templates powered by Handlebars.js, and a router for managing application state.
  • is a full-stack (client-server) JavaScript framework designed exclusively for SPAs. It features simpler data binding than Angular, Ember or ReactJS, and uses the and a to automatically propagate data changes to clients in real-time without requiring the developer to write any synchronization code. Full stack reactivity ensures that all layers, from the database to the templates, update themselves automatically when necessary. Ecosystem packages such as Server Side Rendering address the problem of Search Engine Optimization.
  • is a JavaScript client framework for mobile, desktop and web. It is similar to, but is newer, more standards-compliant, and utilizes a modular approach. Aurelia was written with next-generation.[]
  • (commonly referred to as Vue; pronounced /vjuː/, like view) is an open-source progressive JavaScript framework for building user interfaces.
  • (sometimes styled React.js or ReactJS) is a for building. It is maintained by, and a community of individual developers and corporations. The biggest claimed advantage of React is accessibility - basically any developer familiar with HTML can create React applications. Another claimed advantage is the opportunity to create web and mobile applications using the same technology stack. Several companies use React with Redux library, which lets developers create complex, but scalable web applications.
  • is a full-stack library that adopts data-driven principles from Netflix's Falcor, Facebook's Relay, and Om Next's adaptations of reactive, functional, data-driven software. It leverages React underneath for raw rendering, gaining all of the advantages of that platform, but provides a clear full-stack model similar to Redux, but using immutable data to gain the advantages of functional programming. It has a pluggable architecture that makes it possible to seamlessly integrate any back-end resources, and has the distinction of providing a support viewer technology that allows developers to debug against the real UI state history of an in-the-field client's session. Websockets are supported as an option and allow one to create the advanced behaviors of with very little code. []

Ajax[]

The most prominent technique currently being used is. Predominantly using the /ActiveX Object(deprecated) object from JavaScript, other Ajax approaches include using IFRAME or script HTML elements. Popular libraries like, which normalize Ajax behavior across browsers from different manufacturers, have further popularized the Ajax technique.

Websockets[]

are a bidirectional stateful real-time client-server communication technology part of the HTML5 specification, superior to Ajax in terms of performance and simplicity.

Server-sent events[]

(SSEs) is a technique whereby servers can initiate data transmission to browser clients. Once an initial connection has been established, an event stream remains open until closed by the client. SSEs are sent over traditional HTTP and have a variety of features that WebSockets lack by design such as automatic reconnection, event IDs, and the ability to send arbitrary events.

Browser beim kennenlernen rar machen plugins[]

Although this method is outdated, asynchronous calls to the server may also be achieved using browser plug-in technologies such as,, or.

Data transport (XML, JSON and Ajax)[]

Requests to the server typically result in either raw data (e.g., or ), or new being returned. In the case where HTML is returned by the server, JavaScript on the client updates a partial area of the DOM (). When raw data is returned, often a client-side JavaScript / () process (and in the case of JSON a ) is used to translate the raw data into HTML, which is then used to update a partial area of the DOM.

Server architecture[]

Thin server architecture[]

An SPA moves logic from the server to the client. This results in the role of the web server evolving into a pure data API or web service. This architectural shift has, in some circles, been coined "Thin Server Architecture" to highlight that complexity has been moved from the server to the client, with the argument that this ultimately reduces overall complexity of the system.

Thick stateful server architecture[]

The server keeps the necessary state in memory of the client state of the page. In this way, when any request hits the server (usually user actions), the server sends the appropriate HTML and/or JavaScript with the concrete changes to bring the client to the new desired state (usually adding/deleting/updating a part of the client DOM). At the same time, the state in server is updated. Most of the logic is executed on the server, and HTML is usually also rendered on the server. In some ways, the server simulates a web browser, receiving events and performing delta changes in server state which are automatically propagated to client.

This approach needs more server memory and server processing, but the advantage is a simplified development model because a) the application is usually fully coded in the server, and b) data and UI state in the server are shared in the same memory space with no need for custom client/server communication bridges.

Thick stateless server architecture[]

This is a variant of the stateful server approach. The client page sends data representing its current state to the server, usually through Ajax requests. Using this data, the server is able to reconstruct the client state of the part of the page which needs to be modified and can generate the necessary data or code (for instance, as JSON or JavaScript), which is returned to the client to bring it to a new state, usually modifying the page DOM tree according to the client action which motivated the request.

This approach requires that more data be sent to the server and may require more computational resources per request to partially or fully reconstruct the client page state in the server. At the same time, this approach is more easily scalable because there is no per-client page data kept in the server and, therefore, Ajax requests can be dispatched to different server nodes with no need for session data sharing or server affinity.

Running locally[]

Some SPAs may be executed from a local file using the. This gives users the ability to download the SPA from a server and run the file from a local storage device, without depending on server connectivity. If such an SPA wants to store and update data, it must use browser-based. These applications benefit from advances available with.

Challenges with the SPA model[]

Because the SPA is an evolution away from the stateless page-redraw model that browsers were originally designed for, some new challenges have emerged. Each of these problems has an effective solution with:

  • Client-side JavaScript libraries addressing various issues.
  • Server-side web frameworks that specialize in the SPA model.
  • The evolution of browsers and the HTML5 specification designed for the SPA model.

Search engine optimization[]

Because of the lack of JavaScript execution on crawlers of some popular, SEO () has historically presented a problem for public facing websites wishing to adopt the SPA model.

Between 2009 to 2015, proposed and then recommended an "AJAX crawling scheme" using an initial exclamation mark in fragment identifiers for stateful pages (#!). Special behavior must be implemented by the SPA site to allow extraction of relevant metadata by the search engine's crawler. For search engines that do not support this URL hash scheme, the hashed URLs of the SPA remain invisible. These "hash-bang" URIs have been considered problematic by a number of writers including Jeni Tennison at the W3C because they make pages inaccessible to those who do not have activated in their browser. They also break headers as browsers are not allowed to send the fragment identifier in the Referer header. In 2015, Google deprecated their hash-bang AJAX crawling proposal.

Alternatively, applications may render the first page load on the server and subsequent page updates on the client. This is traditionally difficult, because the rendering code might need to be written in a different language or framework on the server and in the client. Using logic-less templates, cross-compiling from one language to another, or using the same language on the server and the client may help to increase the amount of code that can be shared.

Because SEO compatibility is not trivial in SPAs, it's worth noting that SPAs are commonly not used in a context where search engine indexing is either a requirement, or desirable. Use cases include applications that surface private data hidden behind an system. In the cases where these applications are consumer products, often a classic "page redraw" model is used for the applications landing page and marketing site, which provides enough meta data for the application to appear as a hit in a search engine query. Blogs, support forums, and other traditional page redraw artifacts often sit around the SPA that can seed search engines with relevant terms.

Another approach used by server-centric web frameworks like the Java-based is to render any hypertext on the server using the same language and templating technology. In this approach, the server knows with precision the DOM state on the client, any big or small page update required is generated in the server, and transported by Ajax, the exact JavaScript code to bring the client page to the new state executing DOM methods. Developers can decide which page states must be crawlable by web spiders for SEO and be able to generate the required state at load time generating plain HTML instead of JavaScript. In the case of the ItsNat framework, this is automatic because ItsNat keeps the client DOM tree in the server as a Java W3C DOM tree; rendering of this DOM tree in the server generates plain HTML at load time and JavaScript DOM actions for Ajax requests. This duality is very important for SEO because developers can build with the same Java code and pure HTML-based templating the desired DOM state in server; at page load time, conventional HTML is generated by ItsNat making this DOM state SEO-compatible. As of version 1.3, ItsNat provides a new stateless mode, and the client DOM is not kept on the server because, with the stateless mode client, DOM state is partially or fully reconstructed on the server when processing any Ajax request based on required data sent by the client informing the server of the current DOM state; the stateless mode may be also SEO-compatible because SEO compatibility happens at load time of the initial page unaffected by stateful or stateless modes.

There are a couple of workarounds to make it look as though the web site is crawlable. Both involve creating separate HTML pages that mirror the content of the SPA. The server could create an HTML-based version of the site and deliver that to crawlers, or it's possible to use a headless browser such as PhantomJS to run the JavaScript application and output the resulting HTML.

Both of these do require quite a bit of effort, and can end up giving a maintenance headache for the large complex sites. There are also potential SEO pitfalls. If server-generated HTML is deemed to be too different from the SPA content, then the site will be penalized. Running PhantomJS to output the HTML can slow down the response speed of the pages, which is something for which search engines – Google in particular – downgrade the rankings.

Client/Server code partitioning[]

One way to increase the amount of code that can be shared between servers and clients is to use a logic-less template language like or. Such templates can be rendered from different host languages, such as on the server and in the client. However, merely sharing templates typically requires duplication of used to choose the correct templates and populate them with data. Rendering from templates may have negative performance effects when only updating a small portion of the page—such as the value of a text input within a large template. Replacing an entire template might also disturb a user's selection or cursor position, where updating only the changed value might not. To avoid these problems, applications can use or granular manipulation to only update the appropriate parts of the page instead of re-rendering entire templates.

Browser history[]

With an SPA being, by definition, "a single page", the model breaks the browser's design for page history navigation using the Forward/Back buttons. This presents a usability impediment when a user presses the back button, expecting the previous screen state within the SPA, but instead the application's single page unloads and the previous page in the browser's history is presented.

The traditional solution for SPAs has been to change the browser URL's hash in accord with the current screen state. This can be achieved with JavaScript, and causes URL history events to be built up within the browser. As long as the SPA is capable of resurrecting the same screen state from information contained within the URL hash, the expected back button behavior is retained.

To further address this issue, the HTML5 specification has introduced and providing programmatic access to the actual URL and browser history.

Analytics[]

Analytics tools such as rely heavily upon entire new pages loading in the browser, initiated by a new page load. SPAs do not work this way.

After the first page load, all subsequent page and content changes are handled internally by the application, which should simply call beim kennenlernen rar machen a function to update the analytics package. Failing to call said function, the browser never triggers a new page load, nothing gets added to the browser history, and the analytics package has no idea who is doing what on the site.

Adding page loads to an SPA[]

It is possible to add page load events to an SPA using the HTML5 history API; this will help integrate analytics. The difficulty comes in managing this and ensuring that everything is being tracked beim kennenlernen rar machen accurately – this involves checking for missing reports and double entries. Some frameworks provide open source analytics integrations addressing most of the major analytics providers. Developers can integrate them into the application and make sure that everything is working correctly, but there is no need to do everything from scratch.

Speed of initial load[]

Single Page Applications have a slower first page load than server-based applications. This is because the first load has to bring down the framework and the application code before rendering the required view as HTML in the browser. A server-based application just has to push out the required HTML to the browser, reducing the latency and download time.

Speeding up the page load[]

There are some ways of speeding up the initial load of an SPA, such as a heavy approach to caching and lazy-loading modules when needed. But it's not possible to get away from the fact that it needs to download the framework, at least some of the application code, and will most likely hit an API for data before displaying something in the browser. This is a "pay me now, or pay me later" trade-off scenario. The question of performance and wait-times remains a decision that the developer must make.

Page lifecycle[]

An SPA is fully loaded in the initial page load and then page regions are replaced or updated with new page fragments loaded from the server on demand. To avoid excessive downloading of unused features, an SPA will often progressively download more features as they become required, either small fragments of the page, or complete screen modules.

In this way an analogy exists between "states" in an SPA and "pages" in a traditional web site. Because "state navigation" in the same page is analogous to page navigation, in theory, any page-based web site could be converted to single-page replacing in the same page only the changed parts result of comparing consecutive pages in a non-SPA.

The SPA approach on the web is similar to the (SDI) presentation technique popular in native desktop applications.

References[]

  1. ^ Flanagan, David, "JavaScript - The Definitive Guide", 5th ed., O'Reilly, Sebastopol, CA, 2006, p.497
  2. . Falafel Software Blog. Retrieved 2016-01-18. 
  3. . Retrieved 2011-02-03. 
  4. . Retrieved 2012-07-06. 
  5. . Retrieved 2002-04-12. 
  6. . Meteor Blaze is a powerful library for creating live-updating user interfaces. Blaze fulfills the same purpose as Angular, Backbone, Ember, React, Polymer, or Knockout, but is much easier to use. We built it because we thought that other libraries made user interface programming unnecessarily difficult and confusing. 
  7. , March 21, 2012
  8. . Retrieved 31 January 2015. 
  9. blak-it.com, BLAKIT, (2017-10-17).. BLAKIT - IT Solutions. Retrieved 2017-10-19. 
  10. . 2017-11-02. 
  11. . www.computer.org. Retrieved 2016-06-01. 
  12. . W3C. 17 July 2013. 
  13. . www.webrocketx.com. Retrieved 2016-01-21. 
  14. . 
  15. . Retrieved 2014-04-25. 
  16. . Retrieved 2011-12-11. 
  17. . Retrieved 2013-02-20. 
  18. . Retrieved 2011-01-13. 
  19. . Retrieved January 6, 2014. the browser can execute JavaScript and produce content on the fly - the crawler cannot 
  20. . Retrieved January 6, 2014. Historically, Ajax applications have been difficult for search engines to process because Ajax content is produced 
  21. . Google. October 7, 2009. Retrieved July 13, 2011. 
  22. . Google. Retrieved March 4, 2013. 
  23. . W3C Blog. May 12, 2011. Retrieved July 13, 2011. 
  24. . Official Google Webmaster Central Blog. Retrieved 2017-02-23. 
  25. . Retrieved 2013-06-09. 
  26. ^ Holmes, Simone (2015). Getting MEAN with Mongo, Express, Angular, and Node. Manning Publications.  

External links[]

Simplifying Single-Page Applications with ASP.NET MVC Partial Views

Partial Views can make creating Single-Page Applications dramatically easier by better achieving the goals of the MVC design pattern. Here, in TypeScript, is how to leverage Partial Pages to create an AJAX-enabled application in ASP.NET MVC.

In the MVC pattern, Views are supposed to be so brain-dead simple that they don't require testing: all your logic should be in your Controller, which can be tested using test-driven development (TDD) tools. In addition, in the MVC pattern, program logic and presentation are supposed to be loosely coupled. In ASP.NET MVC, changes to the way the application presents itself should only require changes to the HTML in the relevant View -- not changes to the application's program logic. In another I showed how to leverage ASP.NET Partial Views to achieve those goals.

However, that column delivered an extremely traditional solution -- one that depended on posting back the whole page back to the server to retrieve or update data. These days, developers want to create Single Page Applications (SPAs) that engage in AJAX-enabled conversations with the server for all retrieval and update activities. Unfortunately, the resulting Views in these SPAs often contain client-side code with lots and lots of embedded HTML, violating the separation of presentation and program logic.

It doesn't have to be that way. As I'll demonstrate in this column and the next one, Partial Views provide a simpler way to create an "AJAXified" application by leaving your HTML generation where it belongs: in ASP.NET Views that contain nothing but HTML and references to Model properties. This column shows how to structure your client-side code (using the MVVM pattern), by looking at what server-side and client-side code is required by the application and how those two sets of code can start to be integrated (next month's column will look at the details of implementing update activities). Because I'm assuming this is an enterprise application, my client-side code is written in TypeScript (see "Configuring Visual Studio 2012" for more on how to configure a Visual Studio 2012 ASP.NET MVC project for TypeScript and how to get the Visual Studio 2012 toolkit to work with jQuery).


The SPA I'm building initially displays a list of sales orders in a table (that initial display is generated entirely on the server). Each sales order row in that table has two buttons: one to enable editing for the sales order in the row, the other to delete the sales order in the row. At the top of the table there's an add button that users can click to insert a blank row at the end of the table for adding a new sales order. When the table is in either edit or add mode, the add button at the top of the table and the buttons on the rows not being edited are hidden -- only the row in edit or add mode has any buttons: One to save changes and one to discard any changes and return to the initial display. Returning to the initial display also redisplays the buttons on every row and the add button at the top of the table.

First Server-Side Code
My Controller needs three methods to deliver the rows I use in my sales order table. The first method returns a Partial View that displays sales order information as plain text. The method accepts a SalesOrderDTO object (which may just hold a sales order's ID value) and passes that object to another method that returns a complete SalesOrderDTO object. I use the resulting SalesOrderDTO object to generate a Partial View that I return to the user:

 public ActionResult GetForDisplay(SalesOrderDTO so) { SalesOrderDTO s; s = BuildSalesOrderDO(so); return PartialView("RowDisplay", s); } 

The RowDisplay Partial View used in the method has no logic -- only the HTML for a single row, beginning with the edit/remove buttons in the row's first cell. As you can see in Listing 1 each button is flagged with an attribute called data-buttontype that indicates whether the button is used to trigger edits or deletes. The last cell in the row holds the SalesOrderDTO's ID property in a hidden element.

Listing 1: Start of a Display-Only Row
 <td> <div id="buttonseditgroup"> <button type="button" data-buttontype="edit"> <span class="glyphicon glyphicon-pencil" /> </button> <button type="button" data-buttontype="remove"> <span class="glyphicon glyphicon-remove" /> </button> </div> </td> <td> @Html.DisplayFor(m => m.CustomerName) </td> ...cells for other SalesOrderDTO properties... <td> @Html.HiddenFor(m => m.ID) </td> 

My second Controller method is very similar to my first one, except that the method returns a Partial View called RowUpdate:

 public ActionResult GetForEdit(SalesOrderDTO so) { SalesOrderDTO s; s = BuildSalesOrderDTO(so); return PartialView("RowUpdate", s); } 

The RowUpdate Partial View (Listing 2) is similar to RowDisplay, the only differences being the buttons in the first cell ("save" and "cancel" instead of "edit" and "remove") and the cells contain textboxes to support updating the data:

Listing 2: A Row for Updating SalesOrderDTO Properties
 <td> <div id="buttonseditgroup"> <button type="button" data-buttontype='save'> <span class="glyphicon glyphicon-floppy-disk" /> </button> <button type="button" data-buttontype='cancel' > <span class="glyphicon glyphicon-ban-circle" /> </button> </div> </td> <td> <div id="buttonseditgroup"> <button type="button" data-buttontype="save"> <span class="glyphicon glyphicon-disk" /> </button> <button type="button" data-buttontype="cancel"> <span class="glyphicon glyphicon-circle" /> </button> </div> </td> <td> @Html.EditorFor(m => m.CustomerName) </td> ...cells for other SalesOrderDTO properties... <td> @Html.HiddenFor(m => m.ID) </td> 

The third method is the simplest because it doesn't have to retrieve a SalesOrderDTO. This method simply calls a Partial View that returns a row of empty textboxes for adding a new SalesOrderDTO:

 public ActionResult GetForAdd() { return PartialView("RowNew", new SalesOrderDTO()); } 

The RowNew Partial View is almost identical to the RowUpdate Partial View. The only real difference is that the RowUpdate's HTML is used to create a band-new row so it includes tr tags (the RowUpdate's HTML is used to replace the contents of an existing row and, as a result, doesn't require tr tags of its own):

 <tr> <td> <div id="buttonseditgroup"> ...button tags... </div> </td> ...cells for other SalesOrderDTO properties... </tr> 

First Client-Side Code
In my client-side code, I first define a Data Transfer Object (called SalesOrderDTO) that holds all the data for a sales order:

 class SalesOrderDTO { ID: number; CustomerNumber: string; ...remaining SalesOrderDTO properties... } 

My next class is a View Model object (SalesOrderVM) to hold all of the code for handling my screen and communicating with the server. Right at the top, I declare a variable to hold my SalesOrderDTO object:

 class SalesOrderVM { so: SalesOrderDTO; 

In my VM's constructor, I wire up the functions I'll be creating in my VM to the click event of buttons on my page. For the add button at the top of the table, which is always on the page, I just use the jQuery click function to wire up my add button to its function:

 constructor() { $("#addSalesOrderButton").click(this.AddRow); 

However, I keep adding and removing the other buttons on the page. Rather than repeatedly using the jQuery click function to keep those buttons wired up correctly as I add and remove them, I use the jQuery on function. The on function monitors the page (or part of it; in my case, my SalesOrderTable) and wires up events to my buttons as they appear. In this code I use my data-buttontype attribute to identify which buttons are tied to each of the functions in my VM:

 $("#SalesOrderTable").on("click", "[data-buttontype ='edit']", this.EditRow); $("#SalesOrderTable").on("click", "[data-buttontype='save']", this.SaveRow) $("#SalesOrderTable").on("click", "[data-buttontype='cancel']", this.CancelEdit) $("#SalesOrderTable").on("click", "[data-buttontype ='remove']", this.DeleteRow); } } 

As this code implies, I have five functions in my client-side VM:

  • AddRow: Fetches the RowNew Partial View from my Controller and inserts the row at the bottom of the page to allow adding a new sales order.
  • EditRow: Fetches the RowUpdate Partial View from my Controller and replaces the current to allow updating a sales order.
  • SaveRow: Gathers the data from an updateable row and sends it to the server for processing. This function also replaces the updateable version of the row (from RowUpdate) with the row returned by the RowDisplay Partial View.
  • CancelEdit: Handles exiting an updateable row. If the row was in edit mode, the function replaces the row with the RowDisplay Partial View; if the row was in add mode, the function removes the row from the table.
  • DeleteRow: Deletes the sales order in the current row and removes the row from the table.

Next time, I'll show how those functions work and provide the corresponding server-side functions that add, delete and update sales orders.


Zahra Doe Morbi gravida, sem non egestas ullamcorper, tellus ante laoreet nisl, id iaculis urna eros vel turpis curabitur.

3 Comments

Zahra Doejune 2, 2017
Morbi gravida, sem non egestas ullamcorper, tellus ante laoreet nisl, id iaculis urna eros vel turpis curabitur.
Zahra Doejune 2, 2017
Morbi gravida, sem non egestas ullamcorper, tellus ante laoreet nisl, id iaculis urna eros vel turpis curabitur.
Zahra Doejune 2, 2017
Morbi gravida, sem non egestas ullamcorper, tellus ante laoreet nisl, id iaculis urna eros vel turpis curabitur.

Leavy Reply

Your Name (required) Your Name (required) Your Message