siteperf

package module
v0.0.0-...-26e568b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2023 License: MIT Imports: 14 Imported by: 0

README

Website Performance Tools

This is a kitchen-sink repository for my personal website performance tools.

Find Unused CSS

This tool crawls a website to find unused CSS classes based on a provided stylesheet.

Install
go install github.com/bounoable/siteperf/cmd/find-unused-css
Example

To check for unused CSS classes, run this command:

find-unused-css -url google.com -css style.css -limit 100 -out unusued.txt

This command checks the first 100 pages of google.com for CSS classes in style.css that aren't used and saves them to unused.txt. Each line in unused.txt lists an unused class name.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractClasses

func ExtractClasses(css string) ([]string, error)

ExtractClasses extracts class names from a provided CSS string. It returns a sorted, unique list of class names without the leading dot, ensuring that each class name is valid according to CSS naming conventions. If any error occurs during the extraction, an error is returned alongside an empty slice.

func ExtractClassesFromFile

func ExtractClassesFromFile(path string) ([]string, error)

ExtractClassesFromFile reads the CSS file specified by the given path and extracts a sorted list of unique class names found within it. If reading the file fails, it returns an error. Otherwise, it returns a slice of class names without leading dots and ensures that each class name is valid according to CSS naming conventions.

Types

type Finder

type Finder struct {
	// contains filtered or unexported fields
}

Finder locates unused CSS classes within a website starting from a given URL up to a specified limit of pages. It concurrently crawls the site, respects cancellation via context, and logs its progress using a structured logger. Finder provides the ability to identify classes that are not being utilized in any of the visited pages, helping in the optimization and cleanup of CSS resources. It operates with a customizable degree of concurrency, determined by available CPU resources, to efficiently process multiple pages in parallel.

func New

func New(rootURL string, pageLimit int) (*Finder, error)

New initializes a new Finder with the specified root URL and page limit, logging under the "Finder" namespace. It returns a pointer to the newly created Finder and any error that occurred during its creation, such as an invalid root URL.

func (*Finder) FindUnused

func (f *Finder) FindUnused(ctx context.Context, classes []string) ([]string, error)

FindUnused identifies which of the provided CSS class names are not being used across the web pages within the scope defined by the root URL of the Finder instance. It traverses the website, starting from the root URL, and returns a slice of strings representing class names that appear to be unused. If an error occurs during the search process, it also returns an error detailing what went wrong.

Directories

Path Synopsis
cmd
find-unused-css command
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL