Ways to boost performance in an Angular 6.0 application

https://i.stack.imgur.com/Rq9Y2.jpg We have recently developed a cutting-edge application using Angular 6, hosted on an Apache 2.4 server.

To ensure our website is properly crawled by search engines, we set up a local "prerender" instance. Initially, we tried Angular Universal but faced compatibility issues with libraries, prompting us to switch to the prerender solution.

After implementing Google Analytics tracking code and collecting data for a few days, we decided to run the Google PageSpeed Insights tool.

Our PageSpeed Insights score revealed:

https://i.stack.imgur.com/s0qDI.png https://i.stack.imgur.com/cZuvz.png

The Optimization Suggestions provided by PageSpeed Insights are as follows:

  • Reduce server response time: Google indicates that the page takes approximately 3 seconds to load, with most of the delay attributed to prerendering. Caching the prerendered page seems like a straightforward solution, but we welcome any additional recommendations.
  • Enable compression: Google notes that style files (*.css) are not compressed. How can we activate compression? Perhaps a filter on Apache could help, but we are open to suggestions on configuring this effectively.
  • Eliminate render-blocking JavaScript and CSS in above-the-fold content: The report highlights that certain .css and font resources cause rendering delays. Improving this aspect is challenging – do you have any insights?
  • Leverage browser caching: According to the report, image files (.png, .svg, etc.) are cacheable but lack expiration dates. Introducing a filter on Apache may resolve this issue, but we worry about potential challenges when releasing new versions of our Angular application. Any advice on configuring this optimally?

We also analyzed site speed using , yielding the following result:

https://i.stack.imgur.com/NNd25.png The recommended optimizations include:

  • Specify a Vary: Accept-Encoding header: Configuring Apache to incorporate the Header Vary: Accept-Encoding in responses should address this recommendation. Are there potential drawbacks associated with this header, particularly during new Angular application releases?
  • Combine external JavaScript: While some JavaScript files pertain to external tracking tools, three scripts (main.xxx.js, polyfills.xxx.js, runtime.xxx.js) originate from our Angular application. How can we consolidate these into a single file?

Answer №1

After taking some time to enhance the application, we've made several optimizations that we believe could benefit others as well.

Implementing compression: After conducting thorough research, we incorporated a configuration in the .htaccess of our angular application to enable gzip compression for HTML, CSS, JavaScript, Text, XML, and fonts.

For detailed information, please refer to https://httpd.apache.org/docs/2.4/mod/mod_deflate.html and .

<IfModule mod_deflate.c>
  # Compress HTML, CSS, JavaScript, Text, XML and fonts
  (AddOutputFilterByType DEFLATE application/javascript)...
</IfModule>

Utilizing browser caching: As we develop the angular application using ng build --prod, cache busting is employed in naming files like runtime.06daa30a2963fa413676.js. We have also configured an Expires header on static resources by adding the following code snippet to our .htaccess

<IfModule mod_expires.c>
    ExpiresActive On
    (ExpiresByType image/jpg "access 6 month")...
</IfModule>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing Angular 5's ngIf within an ngFor loop to adjust the index to correspond to the specific rows being

Looking for help with filtering ngFor items and getting the correct index count after applying the filter? Click here to view the code sample on StackBlitz Currently, when filtering by "bob", the index counts the real position of the items. However, I am ...

How to turn off validation for md-input-container in Angular 2

While working on a form in Angular 2, I encountered an issue when adding the required attribute to my <input>. The problem resulted in unwanted margins as shown in this image: I am seeking a solution to only apply the second red margin to the input ...

Techniques for Grouping an Array of Objects by a Specific Value Key in Angular

I have the following array that needs to be grouped by section_name in HTML. Additionally, I need to first check if the length of the array values for section_name is greater than zero before displaying the results grouped by section_name. I hope my expl ...

Angular: Retrieve the parameter value from the parent route

Having URLs structured like this: www.yoursite.com/accounts/:accountid/info www.yoursite.com/accounts/:accountid/users and so on. An integer value labeled as accountid is embedded within the URL. Despite using the ActivatedRoute parameters, I am unable ...

Troubleshooting a Docker EPERM issue while attempting to compile an Angular application within a container

Our team is currently in the process of containerizing our existing stack using Docker and Docker Compose. This is a simplified version of our Docker Compose file with the relevant services: version: '3.8' services: #FO angularproject: c ...

The css values for component _nghost-c0 in an Angular application

Recently, I've been delving into Angular 5 and couldn't help but notice the peculiar html tags with ng generated attributes like _nghost-c0 and _nghost-c1... This got me wondering, what exactly do these attributes signify? [_nghost-c3] .employee ...

Experiencing difficulty retrieving individual :id information from a list in MEAN stack

**I'm experiencing issues retrieving a single :id from a list as the data returned is not what I expected... ** GET /article/5b0be8829f734a4e580a43c5 401 3.845 ms - 99 ===> response from my get request my api ===> var express = require(&apos ...

ViewContainerRef fails to render component on the DOM

@Component({ selector: 'my-cmp', template: ` <div #target></div> ` }) export class MyCmp { @ViewChild('target', {read: ViewContainerRef}) target : ViewContainerRef; render() { let component = createComponent(met ...

` `angular2 get the element reference of a component that is not a direct descendant` `

Within my application, the structure is as follows: <fin-header></fin-header> <main></main> <fin-footer></fin-footer> I would like to implement scrolling within the header to a specific component within main. However, ...

"Revolutionizing the way we navigate: Angular's innovative

Presently, my focus is on incorporating route transitions into my project. I've employed a component that appears on click and triggers the corresponding service function: routeTransition(destination) { if (this.router.url !== destination) { t ...

Ensure that Angular resolver holds off until all images are loaded

Is there a way to make the resolver wait for images from the API before displaying the page in Angular? Currently, it displays the page first and then attempts to retrieve the post images. @Injectable() export class DataResolverService implements Resolv ...

Updating the parameters when clicking on each pagination button: A guide

Does anyone have advice on implementing pagination? I am currently working on loading a datatable with a few records initially. Once the page is loaded, I want to be able to click on pagination buttons like next or any pagination buttons to display a new s ...

An issue arises following an upgrade in Angular from version 9 to version 10, where the property 'propertyName' is being utilized before it has been initialized

I've spent time looking on Google, Github, and Stackoverflow for a solution to this error, but I'm still struggling to fix it. Can anyone offer a suggestion or help? Recently, I upgraded my Angular project from version 9 to version 10, and after ...

ag-grid-angular failing to present information in a table layout

I have implemented ag-grid-angular to showcase data in a structured table format, but the information appears jumbled up in one column. The data for my ag-grid is sourced directly from the raw dataset. https://i.stack.imgur.com/sjtv5.png Below is my com ...

Embracing PWAs with subdomains – seamless installation

One of my Progressive Web Applications (PWA) called app A contains a link to another app, app B. Initially, I hosted both apps on the same subdomain (for example: ) and everything worked perfectly - installing app A also installed app B. However, when I a ...

A step-by-step guide on recovering information from a JSON file within Angular 12

Being a novice developer, I have taken on the challenge of creating a quiz application using Angular 12 to enhance my coding skills. However, I've hit a roadblock when it comes to retrieving data with questions and answers from a JSON file. Despite su ...

Angular 4: Modifying the URL without the Component being Displayed

I'm currently facing an issue where I am attempting to link a component from one component using routerLink = "selected" const routes: Routes = [ { path: '', children: [ { path: 'account&apo ...

Trouble retrieving query parameters from a URL while trying to access URL parameters from a module

I am currently learning angular and facing a small problem that I'm unsure how to solve. My module looks like this: const hostHandler = setContext((operation: any, context: any) => ({ headers: { ...context?.headers, 'X-Location-Hostn ...

When using ngModel, the Tinymce Angular 2+ templates do not initially replace values, whereas they do when templates are inserted by the user

In my Angular 7 app, I am utilizing the TinyMCE editor component. When I insert a template variable into the editor: <span class="data-variable">${variable_name}</span> The variable gets replaced successfully with a value from the `template_r ...

Unit Testing with Angular: Testing the setValueControl function

I am currently in the process of writing unit tests for a straightforward function that assigns controls to various values. fillFormAssociazioneVeicolo() { if (this.aaa) { setValueControl( this.aaa.targaTelaio, this.form.get(&apos ...