Schlagwort: angular

  • How does a Headless Content Management System (CMS) work

    History of Content Management Systems

    Content Management Systems as we use them today go back to the times when the Internet was invented by Tim Berners-Lee in 1990. Data and Content had to be stored somewhere — and even more important — had to be maintained and updated. Initially, most contents were created like documents, edited, and stored as static pages. This is enhanced with the need for dynamic content, interaction like commenting, or linking.

    First CMS were still providing static HTML pages, that were rendered server-side by Script Languages like PHP, JSP, ASP, or other template languages or engines that have been created like TWIGHTL, or Freemarker. Allowing to interact with the pages with added forms. Nowadays with Node as JavaScript (we cover this later)

    This came with some problems as to how HTML is used, contents were only available in one format, and the source was created on a server that did not know anything about the device it was rendered on. With upcoming Mobile, but also other IoT devices it was hard to render this content appropriate on all devices. 

    From Static Pages to Headless CMS, From HTML to Modern Layout techniques
    CMS and technology timeline

    What does this mean? 

    While the content was rendered into a unique layer of HTML on the server-side, only CSS was able to design this output. There was a hard binding from Content to HTML. This caused less flexibility and relaunch. Or re-using of content created effort in re-creating the server-side rendering. CSS could always re-create new designs with existing content if HTML is written properly. (Examples like CSS Zengarden are showing this for decades) But this heavily depends on semantic Markup and no Elements used that cause already design (like line breaks, <div> containers that represent design or similar).

    Nowadays we can adjust layout and design with CSS and Media Queries. There were times when browsers were not supporting this well.

    How do traditional CMS monoliths work?

    A traditional CMS is a software that you either install and manage yourself or in a managed server environment. Traditional CMS is also known as “monolithic” because they contain all functions and assumptions for working in a single system. Traditional CMS often offers a visual authoring interface for editing content (WYSIWYG), as they only have one context for displaying the content — usually a website. The system normally offers a direct editing layer on an existing rendered layout.

    Showing a Headless flow, with an API layer and a Monolithic setup where Rendering, Data and Authoring is in one layer
    Headless vs monolithic

    The headless CMS only contains a data layer and authoring. They provide an API for a headless rendering layer that consumes the data. The aforementioned is also one of the challenges. How can you render a WYSIWYG experience when your authoring system does not know about the rendering?

    A new generation of CMS were invented. These often offer additionally Headless on existing systems, like CoreMedia for example, where besides Freemarker Template, a Headless GraphiQL server exists.

    How to consume headless data

    Headless also provides the possibility to get a content hub to ensure “Content first” implementation. Your one base of content will be able to maintain a bucket of additional endpoints.

    The CMS as Content Hub

    This data will be consumed via APIs — below are some examples. 

    Representational state transfer (REST)

    Rest API

    REST is a software architecture style that defines how to create web services. Web services, which conform to the REST architectural style and are known as RESTful Web Services, provide interoperability between computer systems on the Internet. RESTful web services allow the requesting systems to access and manipulate web resources using a set of stateless operations.

    GraphQL

    Flow: Client, GraphQL Server, Data
    GraphQL

    GraphQL is a query language for your API. Also, a server-side connection for executing queries belongs to a type of system to use for your data management. GraphQL is not tied to a personal database or storage engine and is driven by hidden code and data management.

    A GraphQL service will have types and fields for those types. There are functions for each field from each type.

    This is the rising star, as it offers flexibility not known before.

    GROQ

    I mention GROQ though it is not really widely used, but as I see similarities to GraphQL worth sharing.

    Advantages

    Use cases for headless CMS can be the following: You need to build a website with a technology you are familiar with, or web apps that use JavaScript frameworks like VUE, React, Svelte, Web Components, or Angular. Native mobile apps for iOS or Android can be directly consuming content. As you have seen, it’s not limited to websites.

    Where headless helps:

    • Your team is familiar with a special UI Technology.
    • There is a need for A/B tests
    • If you require a client-side rendered Framework like VUE, React, etc
    • Personalization of Content
    • If you have static side generators in place (Gatsby, Jekyll, Middleman, Next, Nuxt, or Eleventy)
    • Mobile Apps or IoT
    • If you need to enhance your E-Commerce data.
    MonolithicHeadless
    Simplicityoo
    Localization++
    Plug-in Uncertainty+
    Cross-Platform+
    Technology Freedom+
    Developer first+
    Comparison of Advantages

    Drawbacks and Challenges 

    Editing your content can be harder for authors on headless systems. Your System is depending on a second screen/system.

    Websites created with traditional CMS, allow customizable zones, and authors can resize and rearrange dynamic content easier. They are not limited to edit dynamic data in a fixed zone. They are enabled to share content easier.

    With headless, authors often can’t customize the placement or presentation much beyond given forms, without implementing configurable content grids. Dragging and dropping components is getting harder, as the components only exist as data and rely on a presentation layer.

    It can be more expensive to implement and the share of costs can get more complicated when only one unique source exists, but multiple layers consume it.

    Search Engine Optimization can also be trickier. Server-side Rendering (SSR) needs to be implemented for deep linking. SSR makes it even more complex. There are some advantages with server-side rendered JavaScript, but it is still an effort to consider. Think twice before considering headless. There can be use-cases where all of the above is not relevant. Usage depends.

    Conclusion

    There is no black and white decision possible. It depends on your team’s skills, your client’s or customers‘ needs, your project setup, and so on. Just make the right decision in the beginning. 

  • Should I use Web components?

    At my current employer we do all kind of Web Applications. We call it Experience Technology. These customer user experiences have different needs. Sometimes we do static content deliverables like temporary marketing campaign pages, or knowledge bases that never get touched again. More often we do enterprise shopping experiences, catalogue maintenance, and other e-commerce platforms.

    Asking someone of my team how to build their next customer user experience I get named: React, VUE, Svelte or at last, Angular. Normally no one tells me yet: Let’s do it native, let’s use Web Components.

    Do I know why?

    Maybe

    Why the frameworks are so common and preferred is having some reasons:

    • They offer a community
    • Searching for an issue or supporting library for sure returns an Stackoverflow entry or an NPM library
    • There is great support by someone that has „already done this“
    • For Business: It is good to have something to sell that everyone knows

    A quick poll

    Doing a quick poll with our experience technologists hardens the opinion.

    Showing React 58%, Angular 3%, VUE 15%, Native Web Components 7%. Other 13%

    Observing the obvious

    Using frameworks and libraries for everything, causes problems that could be prevented. Average weight of a page is increasing. Complexity of generated code too. Views of common frameworks and libraries are often ridiculous complicated and deep nested and adding libraries and grid systems is done with a click. Importing without seeing the direct deeper effect. On top of that, Designers create complex animations and placeholders and forget that we still have low-end devices to support and not an ideal-world fast internet. Accessibility and search, like find-ability is getting worse. When useless containers are nested and semantics are getting lost.

    On top of all, GDPR compliance is bad to achieve as of often third parties are used in a way that makes it hard to know where your customers details are getting shared.

    This directly leads me to the this ask: Do we at all need to use a framework or library? Can’t we use Web components?

    Webcomponents.org tells a clear use case, but why does still no one considers it first place to use it as base in their projects?

    Web components are a set of web platform APIs that allow you to create new custom, reusable, encapsulated HTML tags to use in web pages and web apps. Custom components and widgets build on the Web Component standards, will work across modern browsers, and can be used with any JavaScript library or framework that works with HTML.
    Web components are based on existing web standards. Features to support web components are currently being added to the HTML and DOM specs, letting web developers easily extend HTML with new elements with encapsulated styling and custom behaviour.

    Webcomponents.org

    Would there be any advantage when using them instead of a framework? Long-term for sure. Imagine a situation where Facebook stops support for React, or Google for Angular. Sooner or later libraries might get outdated. The community for sure support it for some years, but it can stop. There is no guarantee that it works long. There are also new Libraries popping out every day.

    As we started writing decoupled user experiences, using micro-services and micro-frontends, we forgot to enable us to create long lasting frontend code, that is maintainable. Instead of using native functionalities, write proper markup and getting accessible and search engine friendly.

    We now create a dependency to a framework that is maybe out-dating soon. Any reason to do so?

    Not really!

    Frameworks and libraries should help us organizing and writing our code and deliverables, but not overtaking our thinking and tooling. It is not reasonable that we deliver whole applications to clients browsers, when the contents never or only every view months change. We should instead build more meaningful smaller applications. We even need to render server side, using JavaScript.

    A quick excursion on what Web Components are

    Using Web components would allow us to get back to standards, using browser supported simple tooling.

    So why should you consider Web components as complement for frameworks and libraries?

    • They are already a standard!
    • They work cross browser (Can I use it?)
    • They are simple and stand-alone
    • They are already used
    • They are future proof!

    The details

    Web components are the wrapper name for a set of techniques that create browser rendered interfaces. They are created through custom elements, shadow DOM, HTML templates and HTML modules. The latter is yet not widely adopted by browsers.

    Custom Element

    Setup a JavaScript file that contains the code for your custom element.

    class MyCustomElement extends HTMLElement {    
      connectedCallback() {
        this.innerHTML = `<p>Some Text</p>`;
      }
    }
    window.customElements.define('my-custom-element',  MyCustomElement)Code-Sprache: JavaScript (javascript)

    You need a DOM node that can initialise it.

    <my-custom-element></my-custom-element>Code-Sprache: HTML, XML (xml)

    Shadow DOM

    With your custom element you can add coloured text in the context of other text paragraphs. You can capsule your styles that only belonging to the needed node.

    const shadowRoot = document.getElementById('fetched').attachShadow({ mode: 'open' });
    shadowRoot.innerHTML = `<style>
    p {
      border: 1px solid red;
      padding: 5px;
    }
    </style>
    <p id="paragraph">Paragraph using <slot></slot></p>`;Code-Sprache: HTML, XML (xml)

    Create some HTML to connect your code with it.

    <span id="fetched">Slot</span>
    <p id="paragraph">Normal Text</p>Code-Sprache: HTML, XML (xml)

    Shadow DOM like shown below will be generated.

    <body>
      <span id="fetched">    
        <#shadow-root>
          <style>
          p {
            border: 1px solid red;
            padding: 5px;
          }
          </style>
          <p id="paragraph">Paragraph using Slot</p>
        </#shadow-root>
      </span>
      <p id="paragraph">Normal Text</p>
    </body>Code-Sprache: HTML, XML (xml)

    Use HTML Templates

    Stay DRY. Use HTML templates. Look at the the above example. If you want to render more paragraphs, you can repeat your <p> or just use a <template>. It is obvious what is wet and what is dry.

    You can use them together with custom elements and shadow root, or alone.

    <template id="template">
      <p></p>
    </template>
    <section id="paragraphs"></section>Code-Sprache: HTML, XML (xml)

    How to render a HTML template.

    const paragraphs = document.getElementById('template');
    const text = [
      { node: 'Text 1' },
      { node: 'Text 2' },
      { node: 'Text 3' }
    ];
    text.forEach(text => {
      const domNode = document.importNode(paragraphs.content, true);
      domNode.querySelector('p').innerHTML = text.node;
      document.getElementById('paragraphs').appendChild(domNode);
    });Code-Sprache: JavaScript (javascript)

    Did I missed HTML Modules?

    Nope. But they are currently considered. So let’s see.

    What else to consider

    Take also into account that all is maintained in a component library. Handled in a DSM provided by InVision, Figma, or Design Kits like Sketch. We need to ensure to reuse our code and Styles. Design Tokens help here. Amazon has Style Dictionary, but there are others. And ideally, have a direct connect to your repository. (More would be subject of a full own post)

    But my client has IE11 as standard browser!

    Ask them why! Seriously!

    If they still insist, and maybe even have a dated soon to be replaced Edge: there are Polyfills available, they render the components as HTML for you.

    Any other input?

    More and more Frameworks and libraries arise that help generating your applications with Web components. They offer build in test ability, design libraries, pattern libraries and more. There are well established ones like Polymer or Stencil. You can find more on the web component page list. So if you do not want to do it manually. Use provided tools. 

    What to do

    There is no golden hammer that makes all your problems a nail. But you should consider re-usability, need of the current implementation, and how long it will exists. Then it can help you making a decision.

    Static rendering for interims campaign pages, knowledge bases, and so on can improve SEO, size, and customer experience. Full blown SPA with a checkout or profile management, and a healthy mixture for catalogue can do their part on this.

    But the base of all should be a Web component. Just do it.

    Resources mentioned and used

    Fun fact

    Yes, you can also make Web components complicated.