SwayReports

Clean Static Reports Script

This script removes unnecessary dynamic functionality from HTML report files while preserving all static page functionality.

What it removes (SAFE for static sites):

What it preserves (ESSENTIAL for static functionality):

Usage

Basic usage (cleans files in-place):

python clean_static_reports.py instructor_reports/*.html
python clean_static_reports.py --backup instructor_reports/*.html

Output to different directory:

python clean_static_reports.py --output-dir cleaned_reports instructor_reports/*.html

Dry run (see what would be done without making changes):

python clean_static_reports.py --dry-run instructor_reports/*.html

Clean all HTML files in multiple directories:

python clean_static_reports.py --backup instructor_reports/*.html html/*.html

Command-line options

Example output

Processing: instructor_reports/gender_tolerance.html
  Created backup: instructor_reports/gender_tolerance.html.bak
  Removing AdGuard script: //local.adguard.org?ts=1750306983708&type=content-script...
  Removing AdGuard script: //local.adguard.org?ts=1750306983708&name=AdGuard%20Extra...
  Removing CodeMirror script: https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.5/codemirror.min.js
  Removing CodeMirror CSS: https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.5/codemirror.min.css
  Removing histogram-title-fixer script
  Removing API interaction script (2046 chars)
  Removing API interaction script (21295 chars)
  ✓ Cleaned successfully
  Size reduction: 130,505 bytes (19.8%)
  Output: instructor_reports/gender_tolerance.html

Completed: 1 successful, 0 failed

Safety features

The script is designed to be very conservative and includes multiple safety checks:

  1. Pattern matching: Only removes scripts with specific API endpoint patterns
  2. Essential functionality check: Preserves scripts that contain critical functionality keywords
  3. Backup option: Always create backups before making changes
  4. Dry run mode: Test what would be changed without making modifications
  5. Conservative approach: When in doubt, the script keeps the code

Requirements

Typical size reduction

Expect 18-22% file size reduction while maintaining 100% of user-visible functionality.

Actual results from processing 16 instructor report files:

Average reduction: 19.8% with 100% functionality preservation.