{"id":1638,"date":"2012-06-19T04:17:57","date_gmt":"2012-06-19T09:17:57","guid":{"rendered":"http:\/\/www.phpied.com\/?p=1638"},"modified":"2012-06-20T03:25:24","modified_gmt":"2012-06-20T08:25:24","slug":"yslow-development-setup","status":"publish","type":"post","link":"https:\/\/www.phpied.com\/yslow-development-setup\/","title":{"rendered":"YSlow development: setup"},"content":{"rendered":"<p><a href=\"https:\/\/www.phpied.com\/yslow-development-getting-started\/\" title=\"YSlow development: getting started\">As promised<\/a>, let's setup for YSlow development using the easiest option - the bookmarklet version. The journey of conquering the world with your rules and extensions... starts with the first step.<\/p>\n<h2>Checkout<\/h2>\n<p>First you need to get teh codez. Go to the <a href=\"https:\/\/github.com\/marcelduran\/yslow\/\">Github repository<\/a> and click that big ol' Fork button. Then checkout the repository somewhere.<\/p>\n<p>Alternatively, if you don't have a github account and don't care to install and deal with git on your computer, this is OK. Just download the repository as a 1.1MB zip file from:<\/p>\n<p><a href=\"https:\/\/github.com\/marcelduran\/yslow\/zipball\/master\">https:\/\/github.com\/marcelduran\/yslow\/zipball\/master<\/a><\/p>\n<h2>Make<\/h2>\n<p>For this next step you need <code>make<\/code>. Good luck if you're on Windows. On Mac, seems like the most \"blessed\" version you can by installing <a href=\"https:\/\/developer.apple.com\/downloads\/index.action?=command%20line%20tools\">this package<\/a> called Command Line Tools for Xcode. Which (I'm not sure but probably) also requires Xcode. Xcode in the App Store. It's about 1.5GB. You go, I'll wait.<\/p>\n<p>In the top directory of the code you've downloaded, there's a <a href=\"https:\/\/github.com\/marcelduran\/yslow\/blob\/master\/README.md\">readme<\/a> and <a href=\"https:\/\/github.com\/marcelduran\/yslow\/blob\/master\/src\">\/src<\/a> (where it gets interesting) and a <a href=\"https:\/\/github.com\/marcelduran\/yslow\/blob\/master\/Makefile\">Makefile<\/a>.<\/p>\n<p>Since we're building the bookmarklet we'll go like:<\/p>\n<pre>$ make bookmarklet<\/pre>\n<p>But. Not yet. First things first.<\/p>\n<p>The bookmarklet consists of one largish JS file and one smallish CSS. The bookmark that you'll click in the browser will load the JS file. Then the JS needs to know where to find the CSS. So you need a big of config.<\/p>\n<p>If you look in <a href=\"https:\/\/github.com\/marcelduran\/yslow\/tree\/master\/src\/bookmarklet\">\/src\/bookmarklet<\/a> you'll see some config-*.js files. You need a new one for you too.<\/p>\n<p>Let's say you'll host the bookmarklet at <code><a href=\"https:\/\/www.phpied.com\/files\/yslow\">https:\/\/www.phpied.com\/files\/yslow<\/a><\/code>.<\/p>\n<p>You start by copying config-local.js:<\/p>\n<pre>$ cp src\/bookmarklet\/config-local.js src\/bookmarklet\/config-phpied.js<\/pre>\n<p>Next you edit one line there so it looks like:<\/p>\n<div class=\"hl-main\">\n<pre><span class=\"hl-code\"> \r\n<\/span><span class=\"hl-identifier\">YUI<\/span><span class=\"hl-code\">.<\/span><span class=\"hl-identifier\">add<\/span><span class=\"hl-brackets\">(<\/span><span class=\"hl-quotes\">'<\/span><span class=\"hl-string\">yslow-config<\/span><span class=\"hl-quotes\">'<\/span><span class=\"hl-code\">, <\/span><span class=\"hl-reserved\">function<\/span><span class=\"hl-code\"> <\/span><span class=\"hl-brackets\">(<\/span><span class=\"hl-identifier\">Y<\/span><span class=\"hl-brackets\">)<\/span><span class=\"hl-code\"> <\/span><span class=\"hl-brackets\">{<\/span><span class=\"hl-code\">\r\n    <\/span><span class=\"hl-identifier\">Y<\/span><span class=\"hl-code\">.<\/span><span class=\"hl-identifier\">namespace<\/span><span class=\"hl-brackets\">(<\/span><span class=\"hl-quotes\">'<\/span><span class=\"hl-string\">YSLOW<\/span><span class=\"hl-quotes\">'<\/span><span class=\"hl-brackets\">)<\/span><span class=\"hl-code\">.<\/span><span class=\"hl-identifier\">config<\/span><span class=\"hl-code\"> = <\/span><span class=\"hl-brackets\">{<\/span><span class=\"hl-code\">\r\n        <\/span><b><span class=\"hl-identifier\">host<\/span><span class=\"hl-code\">: <\/span><span class=\"hl-quotes\">'<\/span><span class=\"hl-string\">https:\/\/www.phpied.com\/files\/yslow\/<\/span><span class=\"hl-quotes\">'<\/span><span class=\"hl-code\">,\r\n        <\/span><\/b><span class=\"hl-identifier\">js<\/span><span class=\"hl-code\">: <\/span><span class=\"hl-quotes\">'<\/span><span class=\"hl-string\">{{BOOKMARKLET_JS}}<\/span><span class=\"hl-quotes\">'<\/span><span class=\"hl-code\">,\r\n        <\/span><span class=\"hl-identifier\">css<\/span><span class=\"hl-code\">: <\/span><span class=\"hl-quotes\">'<\/span><span class=\"hl-string\">{{BOOKMARKLET_CSS}}<\/span><span class=\"hl-quotes\">'<\/span><span class=\"hl-code\">\r\n    <\/span><span class=\"hl-brackets\">}<\/span><span class=\"hl-code\">;\r\n<\/span><span class=\"hl-brackets\">}<\/span><span class=\"hl-brackets\">)<\/span><span class=\"hl-code\">;<\/span><\/pre>\n<\/div>\n<p>Now, time to build! All you need is to run `make` pointing to your config:<\/p>\n<pre>$ make bookmarklet config=\"config-phpied.js\"\r\n\r\nbuilding YUI...\r\ndone\r\nbuilding BOOKMARKLET files...\r\ndone\r\nmerging YUI and BOOKMARKLET...\r\ndone<\/pre>\n<p>Now look what you've done! You've created a directory <code>build\/bookmarklet<\/code><\/p>\n<pre>$ ls build\/bookmarklet\/\r\nyslow-bookmarklet.js\tyslow-style.css<\/pre>\n<p>(you can also do `make pkg-bookmarklet` to create a minified version, but let's keep things readable for now)<\/p>\n<h2>Host<\/h2>\n<p>Now you need to copy the .js and .css to a server of your choosing, be it localhost or now. I'd go:<\/p>\n<pre>$ scp build\/bookmarklet\/* username@perfplanet.com:~\/phpied.com\/files\/yslow<\/pre>\n<h2>Install bookmarklet<\/h2>\n<p>If you've already installed the YSlow bookmarklet in your browser, you can go and edit the location of the JS file. If not, visit <a href=\"http:\/\/yslow.org\/mobile\">http:\/\/yslow.org\/mobile<\/a> for the instructions.<\/p>\n<p>This page will update the hash in the url to:<\/p>\n<pre>http:\/\/yslow.org\/mobile\/#javascript:.....more stuff...<\/pre>\n<p>All you need to do is change <b>yslow.org<\/b> to your location, e.g. <b>phpied.com\/files\/yslow<\/b>.<\/p>\n<p>Then bookmark the page.<\/p>\n<p>Then edit the bookmark and remove everything up to and including the hash # (http:\/\/yslow.org\/mobile\/#)<\/p>\n<h2>Run<\/h2>\n<ol>\n<li>Go to a page of your choosing<\/li>\n<li>Click the bookmarklet<\/li>\n<li>See YSlow UI appears<\/li>\n<\/ol>\n<p>It works so well that you even need to look at a network analyzer to believe it's really using your own hosted version.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/www.phpied.com\/wp-content\/uploads\/2012\/06\/yslow.jpg\" alt=\"\" title=\"yslow\" width=\"650\" height=\"544\" class=\"aligncenter size-full wp-image-1639\" srcset=\"https:\/\/www.phpied.com\/wp-content\/uploads\/2012\/06\/yslow.jpg 650w, https:\/\/www.phpied.com\/wp-content\/uploads\/2012\/06\/yslow-300x251.jpg 300w\" sizes=\"(max-width: 650px) 100vw, 650px\" \/><\/p>\n<p>And your own version is just a big javascript really, so there's nothing new and nothing extension-y to learn like XUL or manifest.json. You can just start tinkering immediately. You can even edit that .js file directly and make it like a real tight web programming loop: save-refresh. Or you can edit source files and rebuild, repush combining the make and scp commands. Let's do that.<\/p>\n<h2>Console: the best friend<\/h2>\n<p>YSlow takes extra care to run unobtrusively to the page. In an iframe, not leaving any globals behind. Meh, I want to play in the console. So I want to access the two globals: <code>YUI<\/code> and <code>YSLOW<\/code>. Let's see how you add your codes to YSlow. That's as good an exercise as any.<\/p>\n<p>Create a new file in a new dir like: <code>mystuff\/stuff.js<\/code> with this in it:<\/p>\n<div class=\"hl-main\">\n<pre><span class=\"hl-identifier\">parent<\/span><span class=\"hl-code\">.<\/span><span class=\"hl-identifier\">YUI<\/span><span class=\"hl-code\"> = <\/span><span class=\"hl-identifier\">parent<\/span><span class=\"hl-code\">.<\/span><span class=\"hl-identifier\">YUI<\/span><span class=\"hl-code\"> || <\/span><span class=\"hl-identifier\">YUI<\/span><span class=\"hl-code\">;\r\n<\/span><span class=\"hl-identifier\">parent<\/span><span class=\"hl-code\">.<\/span><span class=\"hl-identifier\">YSLOW<\/span><span class=\"hl-code\"> = <\/span><span class=\"hl-identifier\">YSLOW<\/span><span class=\"hl-code\">;<\/span><\/pre>\n<\/div>\n<p>You know YSlow bookmarklet runs in an iframe, so we want to expose the iframe's two globals to the parent.<\/p>\n<p>Add your new file in the <code>Makefile<\/code> in the <code>bookmarklet-files<\/code> part:<\/p>\n<div class=\"hl-main\">\n<pre><span class=\"hl-code\"> \r\n<\/span><span class=\"hl-identifier\">bookmarklet<\/span><span class=\"hl-code\">-<\/span><span class=\"hl-identifier\">files<\/span><span class=\"hl-code\">:\r\n  <\/span><span class=\"hl-var\">@echo<\/span><span class=\"hl-code\"> <\/span><span class=\"hl-quotes\">&quot;<\/span><span class=\"hl-string\">building BOOKMARKLET files...<\/span><span class=\"hl-quotes\">&quot;<\/span><span class=\"hl-code\">\r\n  <\/span><span class=\"hl-var\">@if<\/span><span class=\"hl-code\"> <\/span><span class=\"hl-brackets\">[<\/span><span class=\"hl-code\"> ! -<\/span><span class=\"hl-identifier\">d<\/span><span class=\"hl-code\"> $<\/span><span class=\"hl-brackets\">(<\/span><span class=\"hl-identifier\">BUILD_BOOKMARKLET<\/span><span class=\"hl-brackets\">)<\/span><span class=\"hl-code\"> <\/span><span class=\"hl-brackets\">]<\/span><span class=\"hl-code\">; <\/span><span class=\"hl-reserved\">then<\/span><span class=\"hl-code\"> <\/span><span class=\"hl-identifier\">mkdir<\/span><span class=\"hl-code\"> -<\/span><span class=\"hl-identifier\">p<\/span><span class=\"hl-code\"> $<\/span><span class=\"hl-brackets\">(<\/span><span class=\"hl-identifier\">BUILD_BOOKMARKLET<\/span><span class=\"hl-brackets\">)<\/span><span class=\"hl-code\">; <\/span><span class=\"hl-reserved\">fi<\/span><span class=\"hl-code\">\r\n  <\/span><span class=\"hl-var\">@cat<\/span><span class=\"hl-code\"> $<\/span><span class=\"hl-brackets\">(<\/span><span class=\"hl-identifier\">SRC_COMMON<\/span><span class=\"hl-brackets\">)<\/span><span class=\"hl-code\">\/<\/span><span class=\"hl-identifier\">yslow<\/span><span class=\"hl-code\">.<\/span><span class=\"hl-identifier\">js<\/span><span class=\"hl-code\"> \\\r\n            $<\/span><span class=\"hl-brackets\">(<\/span><span class=\"hl-identifier\">SRC_COMMON<\/span><span class=\"hl-brackets\">)<\/span><span class=\"hl-code\">\/<\/span><span class=\"hl-identifier\">version<\/span><span class=\"hl-code\">.<\/span><span class=\"hl-identifier\">js<\/span><span class=\"hl-code\"> \\\r\n            <\/span><span class=\"hl-brackets\">[<\/span><span class=\"hl-code\">....<\/span><span class=\"hl-brackets\">]<\/span><span class=\"hl-code\">\r\n            $<\/span><span class=\"hl-brackets\">(<\/span><span class=\"hl-identifier\">SRC_COMMON<\/span><span class=\"hl-brackets\">)<\/span><span class=\"hl-code\">\/<\/span><span class=\"hl-identifier\">peeler<\/span><span class=\"hl-code\">.<\/span><span class=\"hl-identifier\">js<\/span><span class=\"hl-code\"> \\\r\n            $<\/span><span class=\"hl-brackets\">(<\/span><span class=\"hl-identifier\">SRC_COMMON<\/span><span class=\"hl-brackets\">)<\/span><span class=\"hl-code\">\/<\/span><span class=\"hl-identifier\">peeler<\/span><span class=\"hl-code\">-<\/span><span class=\"hl-identifier\">bm<\/span><span class=\"hl-code\">-<\/span><span class=\"hl-identifier\">ch<\/span><span class=\"hl-code\">-<\/span><span class=\"hl-identifier\">ph<\/span><span class=\"hl-code\">.<\/span><span class=\"hl-identifier\">js<\/span><span class=\"hl-code\"> \\\r\n            $<\/span><span class=\"hl-brackets\">(<\/span><span class=\"hl-identifier\">SRC_BOOKMARKLET<\/span><span class=\"hl-brackets\">)<\/span><span class=\"hl-code\">\/$<\/span><span class=\"hl-brackets\">(<\/span><span class=\"hl-identifier\">BM_CONFIG<\/span><span class=\"hl-brackets\">)<\/span><span class=\"hl-code\"> \\\r\n            <\/span><b><span class=\"hl-identifier\">mystuff<\/span><span class=\"hl-code\">\/<\/span><span class=\"hl-identifier\">stuff<\/span><span class=\"hl-code\">.<\/span><span class=\"hl-identifier\">js<\/span><span class=\"hl-code\"> \\<\/span><\/b>\r\n            $<span class=\"hl-brackets\">(<\/span><span class=\"hl-identifier\">SRC_BOOKMARKLET<\/span><span class=\"hl-brackets\">)<\/span><span class=\"hl-code\">\/<\/span><span class=\"hl-identifier\">controller<\/span><span class=\"hl-code\">.<\/span><span class=\"hl-identifier\">js<\/span><span class=\"hl-code\"> | \\\r\n            <span class=\"hl-reserved\">sed<\/span><span class=\"hl-code\"> <\/span><span class=\"hl-identifier\">s<\/span><span class=\"hl-code\">\/<\/span><span class=\"hl-brackets\">{<\/span><span class=\"hl-brackets\">{<\/span><span class=\"hl-identifier\">YSLOW_VERSION<\/span><span class=\"hl-brackets\">}<\/span><span class=\"hl-brackets\">}<\/span><span class=\"hl-code\">\/$<\/span><span class=\"hl-brackets\">(<\/span><span class=\"hl-identifier\">YSLOW_VERSION<\/span><span class=\"hl-brackets\">)<\/span><span class=\"hl-code\">\/ | \\\r\n            <\/span><span class=\"hl-reserved\">sed<\/span><span class=\"hl-code\"> <\/span><span class=\"hl-identifier\">s<\/span><span class=\"hl-code\">\/<\/span><span class=\"hl-brackets\">{<\/span><span class=\"hl-brackets\">{<\/span><span class=\"hl-identifier\">BOOKMARKLET_JS<\/span><span class=\"hl-brackets\">}<\/span><span class=\"hl-brackets\">}<\/span><span class=\"hl-code\">\/$<\/span><span class=\"hl-brackets\">(<\/span><span class=\"hl-identifier\">BOOKMARKLET_JS<\/span><span class=\"hl-brackets\">)<\/span><span class=\"hl-code\">\/ | \\\r\n            <\/span><span class=\"hl-reserved\">sed<\/span><span class=\"hl-code\"> <\/span><span class=\"hl-identifier\">s<\/span><span class=\"hl-code\">\/<\/span><span class=\"hl-brackets\">{<\/span><span class=\"hl-brackets\">{<\/span><span class=\"hl-identifier\">BOOKMARKLET_CSS<\/span><span class=\"hl-brackets\">}<\/span><span class=\"hl-brackets\">}<\/span><span class=\"hl-code\">\/$<\/span><span class=\"hl-brackets\">(<\/span><span class=\"hl-identifier\">BOOKMARKLET_CSS<\/span><span class=\"hl-brackets\">)<\/span><span class=\"hl-code\">\/ \\\r\n            &gt; $<\/span><span class=\"hl-brackets\">(<\/span><span class=\"hl-identifier\">BUILD_BOOKMARKLET<\/span><span class=\"hl-brackets\">)<\/span><span class=\"hl-code\">\/$<\/span><span class=\"hl-brackets\">(<\/span><span class=\"hl-identifier\">BOOKMARKLET_YSLOW_JS<\/span><span class=\"hl-brackets\">)<\/span><\/span><\/pre>\n<\/div>\n<p>Then build and deploy:<\/p>\n<pre>$ make bookmarklet config=\"config-phpied.js\"; \\\r\n  scp build\/bookmarklet\/* \\\r\n  username@perfplanet.com:~\/phpied.com\/files\/yslow<\/pre>\n<p>Now you can run the bookmarklet and start exploring what's available to you in the console:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/www.phpied.com\/wp-content\/uploads\/2012\/06\/yslow2.jpg\" alt=\"\" title=\"yslow2\" width=\"511\" height=\"570\" class=\"aligncenter size-full wp-image-1640\" srcset=\"https:\/\/www.phpied.com\/wp-content\/uploads\/2012\/06\/yslow2.jpg 511w, https:\/\/www.phpied.com\/wp-content\/uploads\/2012\/06\/yslow2-268x300.jpg 268w\" sizes=\"(max-width: 511px) 100vw, 511px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>As promised, let&#8217;s setup for YSlow development using the easiest option &#8211; the bookmarklet version. The journey of conquering the world with your rules and extensions&#8230; starts with the first step. Checkout First you need to get teh codez. Go to the Github repository and click that big ol&#8217; Fork button. Then checkout the repository [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[43,47],"tags":[],"_links":{"self":[{"href":"https:\/\/www.phpied.com\/wp-json\/wp\/v2\/posts\/1638"}],"collection":[{"href":"https:\/\/www.phpied.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.phpied.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.phpied.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.phpied.com\/wp-json\/wp\/v2\/comments?post=1638"}],"version-history":[{"count":0,"href":"https:\/\/www.phpied.com\/wp-json\/wp\/v2\/posts\/1638\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.phpied.com\/wp-json\/wp\/v2\/media?parent=1638"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.phpied.com\/wp-json\/wp\/v2\/categories?post=1638"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.phpied.com\/wp-json\/wp\/v2\/tags?post=1638"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}