What is Astro and why you should consider using it to build your website

Astro is one of the most notable projects of the year. Astro is a tool to build web sites that load faster because they ship less JavaScript.

Risingstars

How can you build a faster website?

To build a faster website you need to ship less code. Astro is a kind of static site builder that delivers lightning-fast performance with a modern developer experience.

With Astro you can build your site using your own framework like React, Vue or just HTML and JavaScript. Astro then renders the entire page to static HTML, removing all JavaScript from your final build by default.

If there is a real need for some Javscript component, Astro loads it when it’s visible.

It supports all the npm packages, CSS modules etc and is SEO enabled.

How it works?

Astro works like a static site generator which means it will generate a static HTML site for you during build, with almost no Javascript. It’s pretty obvious that this will be much faster compared to a site with Javascript.

When a component, like add to cart or carousel, needs some JavaScript, it loads that component. The rest of your site continues to exist as static, lightweight HTML. This new approach to web architecture is called islands architecture.

Sample project is available at Github – https://github.com/ankur-srivastava/astro-blog

Android Basics – Learn how to use Bound Services

So far you have learnt about the Started Service, which runs indefinitely till it completes.

A Bound Service is attached to the component which invokes it. If an Activity invokes this service then the Bound Service will depend on the LifeCycle of the Activity.

An example can be if you are using location based service.

To understand this you are going to create a new Service class – DistanceTraveledService.

This Service class will track the distance the user travels. After calculating the distance it will return the value to the MainActivity class.

Let’s look at the steps needed:

  1. Create a Binder class which will connect the Service class with MainActivity.
  2. Create a LocationListener which will track location changes. Register this with DistanceTraveledService class.
  3. Create a public method getDistance() in the DistanceTraveledService. This method will be called by the MainActivity.

The following diagram shows the components needed. In the next Article you will start making the changes.

BoundService