DEV Community

ogbotemi-2000
ogbotemi-2000

Posted on

A smart contract that accepts a URL and return a JSON of only used CSS styles

This is a submission for the Build Better on Stellar: Smart Contract Challenge : Build a dApp

What I Built

A smart contract on Stellar testnet that will receive a website URL and return a JSON of the used styles on the page as an improvement over this webapp I had deployed months ago:https://rmrf-css.vercel.app/

Demo

With a progressive UI, the user in onboarded on the useful aspects of the webapp as seen at the URL above.

The final logic flow that offers a customizable speed of execution
Image description

My Code

Reboot via Stellar blockchain

An experiment at trying HTTP requests for my first time in rust while communicating directly with the API layer of the webapp

use reqwest;

// tokio let's us use "async" on our main function
#[tokio::main]
async fn main() {
    // chaining .await will yield our query result
    let result = reqwest::get("https://rmrf-css.vercel.app?url=https://google.com").await;

    println!("{:?}", result)
}

Enter fullscreen mode Exit fullscreen mode

Journey

The algorithm to trim css files has a very good performance and rewriting it in Rust will offer unreal speeds.

Going further

The old algorithm for trimming, available at the provided URL has been rewritten first, in Javascript and eventually, it will be rewritten in Rust.

If the Javascript version of the rewritten algorithm can boast a speed of 1.5s for unminified TailwindCSS against over 600 unique classnames, its rust equivalent is expected to be in the range of 60ms and below.

The rewrite will be debuted on the webapp: https://rmrf-css.vercel.app for web enthusiasts to get a whiff of its faster execution.

Join in on the code here!
https://github.com/ogbotemi-2000/rmrf-css-client

Additional Prize Categories: Glorious Game and/or Super Sustainable

Top comments (0)