mincss Documentation Release 0.1 Peter Bengtsson

Similar documents
.. Documentation. Release 0.4 beta. Author

HTML + CSS. ScottyLabs WDW. Overview HTML Tags CSS Properties Resources

.. Documentation. Release Author

User Interaction: jquery

Introduction to WEB PROGRAMMING

yawrap Documentation Release Michal Kaczmarczyk

htmlmin Documentation

HTML 5 and CSS 3, Illustrated Complete. Unit L: Programming Web Pages with JavaScript

cssselect Documentation

welcome to BOILERCAMP HOW TO WEB DEV

linkgrabber Documentation

Deccansoft Software Services

XML: Introduction. !important Declaration... 9:11 #FIXED... 7:5 #IMPLIED... 7:5 #REQUIRED... Directive... 9:11

CS109 Data Science Data Munging

django-revproxy Documentation

Student, Perfect Final Exam May 25, 2006 ID: Exam No CS-081/Vickery Page 1 of 6

Design Document V2 ThingLink Startup

Varargs Training & Software Development Centre Private Limited, Module: HTML5, CSS3 & JavaScript

Portcullis Computer Security.

AP CS P. Unit 2. Introduction to HTML and CSS

django-dajax Documentation

Django Map Widgets Documentation

Scripting for Multimedia LECTURE 5: INTRODUCING CSS3

Receiving Courses Iframe Integration

Chapter 1: Getting Started. You will learn:

yawrap Documentation Release Michal Kaczmarczyk

JavaScript: Events, DOM and Attaching Handlers

Style-Guidelines. Release 0.1

webdriverplus Release 0.1

Django-CSP Documentation

INTRODUCTION TO CSS. Mohammad Jawad Kadhim

Index LICENSED PRODUCT NOT FOR RESALE


django-intercom Documentation

Introduction to Computer Science Web Development

Markup Language. Made up of elements Elements create a document tree

Django Forme Documentation

Web Site Development with HTML/JavaScrip

CS144 Notes: Web Standards

Perfect Student Midterm Exam March 20, 2007 Student ID: 9999 Exam: 7434 CS-081/Vickery Page 1 of 5

CUSTOMER PORTAL. Custom HTML splashpage Guide

Best Practices Chapter 5

The DOM and jquery functions and selectors. Lesson 3

Introduction to HTML & CSS. Instructor: Beck Johnson Week 2

Building a Django Twilio Programmable Chat Application

Web Design and Development ACS-1809

Understanding Angular Directives By Jeffry Houser

AIM. 10 September

More about HTML. Digging in a little deeper

ipython-gremlin Documentation

Some Facts Web 2.0/Ajax Security

Executive Summary. Performance Report for: The web should be fast. Top 5 Priority Issues. How does this affect me?

Introduction to Cascading Style Sheet (CSS)

HTML TIPS FOR DESIGNING.

Lecture : 3. Practical : 2. Course Credit. Tutorial : 0. Total : 5. Course Learning Outcomes

Week 8 Google Maps. This week you ll learn how to embed a Google Map into a web page and add custom markers with custom labels.

Table of contents. DMXzoneUniformManual DMXzone

710 Index Attributes, 127 action attribute, 263 assigning, bottom attribute, domain name attribute, 481 expiration date attribute, 480 8

Downloads: Google Chrome Browser (Free) - Adobe Brackets (Free) -

Python Overpass API Documentation

CE212 Web Application Programming Part 2

Website review google.com

Unifer Documentation. Release V1.0. Matthew S

Data Visualization (CIS/DSC 468)

B. V. Patel Institute of Business Management, Computer & Information Technology, UTU

Website Design (Weekday) By Alabian Solutions Ltd , 2016

Lecture 4: Data Collection and Munging

Executive Summary. Performance Report for: The web should be fast. Top 1 Priority Issues. How does this affect me?

streamio Documentation

Executive Summary. Performance Report for: The web should be fast. Top 5 Priority Issues

IMY 110 Theme 11 HTML Frames

django-rest-framework-datatables Documentation

Table of contents. DMXzone Ajax Form Manual DMXzone

Using Dreamweaver CS6

PASS4TEST. IT Certification Guaranteed, The Easy Way! We offer free update service for one year

Overview. Part I: Portraying the Internet as a collection of online information systems HTML/XHTML & CSS

django-session-security Documentation

Facebook SDK for Python Documentation

Chapter 1 Getting Started with HTML 5 1. Chapter 2 Introduction to New Elements in HTML 5 21

Django EL(Endless) Pagination Documentation

ENRICHING PRIMO RECORDS WITH INFORMATION FROM WORDPRESS. Karsten Kryger Hansen Aalborg University Library

Document Object Model. Overview

Index. alt, 38, 57 class, 86, 88, 101, 107 href, 24, 51, 57 id, 86 88, 98 overview, 37. src, 37, 57. backend, WordPress, 146, 148

Project 3 Web Security Part 1. Outline

tinycss Documentation

DAY 4. Coding External Style Sheets

Block & Inline Elements

Django Map Widgets Documentation

Using Development Tools to Examine Webpages

bottle-rest Release 0.5.0

Interview Question & Answers

Website Design (Weekend) By Alabian Solutions Ltd , 2016

In this project, you ll learn how to use CSS to create an animated sunrise.

Performance Report for: Report generated: Tuesday, June 30, 2015, 3:21 AM -0700

CSCE 120: Learning To Code

Tutorial 1 Getting Started with HTML5. HTML, CSS, and Dynamic HTML 5 TH EDITION

Visualforce & Lightning Experience

scrapekit Documentation

Midterm 1 Review Sheet CSS 305 Sp 06

HTML and CSS COURSE SYLLABUS

Transcription:

mincss Documentation Release 0.1 Peter Bengtsson Sep 27, 2017

Contents 1 Getting started 3 2 Supported Features and Limitations 5 3 API 7 4 Changelog 9 4.1 v0.8.1 (2013-04-05)........................................... 9 4.2 v0.8.0 (2013-02-26)........................................... 9 4.3 v0.7.0 (2013-02-13)........................................... 9 4.4 v0.6.1 (2013-02-12)........................................... 9 4.5 v0.6.0 (2013-02-01)........................................... 9 4.6 v0.5.0 (2013-01-24)........................................... 10 4.7 v0.1 (2013-01-14)............................................ 10 5 Indices and tables 11 i

ii

mincss Documentation, Release 0.1 mincss is a Python library that makes it possible to evaluate which CSS is actually being used. It does this by download the whole page(s) and finds all inline and linked CSS and analyses which selectors are still in use somewhere. Optionally, you can use PhantomJS to download the HTML source from a URL which means it will at least load all the Javascript that gets executed onload. Installation should be as simple as pip install mincss. The code is available on Github. Contents 1

mincss Documentation, Release 0.1 2 Contents

CHAPTER 1 Getting started Suppose you have a page like this: <!doctype html> <html> <head> <style type="text/css">.foo, input:hover { color: black; }.bar { color: blue; } </style> </head> <body> <div id="content"> <p class="foo">foo!</p> </div> </body> </html> And, let s assume that this is available as http://localhost/page.html. Now, let s use mincss as follows: >>> from mincss.processor import Processor >>> p = Processor() >>> p.process('http://localhost/page.html') >>> inline = p.inlines[0] >>> inline.before '\n.foo, input:hover { color: black; }\n.bar { color: blue; }\n ' >>> inline.after '\n.foo { color: black; }\n ' As you can see, it automatically discovered that the input:hover and the.bar selectors are not used in the HTML DOM tree. If you have phantomjs installed and can do things like $ phantomjs --help on your command line you can run mincss like this: 3

mincss Documentation, Release 0.1 >>> from mincss.processor import Processor >>> p = Processor(phantomjs=True) >>> p.process('http://localhost/page-with-javascript.html') 4 Chapter 1. Getting started

CHAPTER 2 Supported Features and Limitations Things that work: Any selector that lxml s CSSSelector can match such as #foo >.bar input[type="submit"] media queries are supported (this is treated as nested CSS basically) keyframes are left untouched You can manually over selectors that should be untouched for things you definitely know will be needed by Javascript code but isn t part of the initial HTML tree. You can analyze multiple URLs and find the common CSS amongst them. (This doesn t work for inline CSS) Comments are left untouched and minute whitespace details are preseved so the generated output looks similar to its input, but with the selectors not needed removed. A proxy server apps is available that can help you preview the result of just one URL. Things that don t yet work: Javascript events that manipulate the DOM tree. You can use PhantomJS to do the downloading but it still won t get every possible piece of HTML generated based on complex Javascript. keyframes are always left untouched even if it s never referenced Broken HTML or broken/invalid CSS isn t supported and good results can not be guaranteed. Things that don t work: link tags wrapped in IE-only style comments (e.g <!--[if lte IE 7]>) is not supported. 5

mincss Documentation, Release 0.1 6 Chapter 2. Supported Features and Limitations

CHAPTER 3 API This is work in progress and is likely to change in future version process.processor([debug=false, preserve_remote_urls=true]) Creates a processor instance that you can feed HTML and URLs. The arguments: debug=false Currently does nothing particular. preserve_remote_urls=true If you run a URL like http://www.example.org that references http://cdn.cloudware.com/foo.css which contains url(/background.png) then the CSS will be rewritten to become url(http://cdn.cloudware.com/background.png) phantomjs=none If True will default to phantomjs, If a string it s assume it s the path to the executable phantomjs path. phantomjs_options={} Additional options/switches to the phantomjs command. This has to be a dict. So, for example {'script-encoding': 'latin1'} becomes --script-encoding=latin1. optimize_lookup=true If true, will make a set of all ids and class names in all processed documents and use these to avoid some expensive CSS query searches. Instances of this allows you to use the following methods: process(*urls) Downloads the HTML from that URL(s) and expects it to be 200 return code. The content will be transformed to a unicode string in UTF-8. Once all URLs have been processed the CSS is analyzed. process_url(url) Given a specific URL it will download it and parse the HTML. This method will download the HTML then called process_html(). process_html(html, url) If you for some reason already have the HTML you can jump straight to this method. Note, you still need to provide the URL where you got the HTML from so it can use that to download any external CSS. The Processor instance will make two attributes available 7

mincss Documentation, Release 0.1 instance.inlines A list of InlineResult instances (see below) instance.links A list of LinkResult instances (see below) InlineResult This is where the results are stored for inline CSS. It holds the following attributes: line Which line in the original HTML this starts on url The URL this was found on before The inline CSS before it was analyzed after The new CSS with the selectors presumably not used removed LinkResult This is where the results are stored for all referenced links to CSS files. i.e. from things like <link rel="stylesheet" href="foo.css"> It contains the following attributes: href The href attribute on the link tag. e.g. /static/main.css before The CSS before it was analyzed after The new CSS with the selectors presumably not used removed 8 Chapter 3. API

CHAPTER 4 Changelog v0.8.1 (2013-04-05) The file download.js was missing from the tarball. v0.8.0 (2013-02-26) Much faster! Unless you pass Processor(optimize_lookup=False) when creating the processor instance. See http://www.peterbe.com/plog/mincss-0.8 v0.7.0 (2013-02-13) Fixed bug with make absolute url of url like http://peterbe.com +./style.css. Thanks @erfaan! v0.6.1 (2013-02-12) The proxy app would turn <script src= foo ></script> into <script src= http://remote/foo />. Same for iframe, textarea and divs. v0.6.0 (2013-02-01) New option, phantomjs that allows you to download the HTML using phantomjs instead of regular Python s urllib. 9

mincss Documentation, Release 0.1 v0.5.0 (2013-01-24) New option preserve_remote_urls to Processor() class. Useful when the hrefs in link tags are of different domain than the URL you re processing. v0.1 (2013-01-14) Initial release. 10 Chapter 4. Changelog

CHAPTER 5 Indices and tables genindex modindex search 11

mincss Documentation, Release 0.1 12 Chapter 5. Indices and tables

Index A api, 5 C changelog, 8 F features, 4 G gettingstarted, 1 13