{"action":"created","issue":{"url":"https://api.github.com/repos/neilime/zf2-assets-bundle/issues/56","repository_url":"https://api.github.com/repos/neilime/zf2-assets-bundle","labels_url":"https://api.github.com/repos/neilime/zf2-assets-bundle/issues/56/labels{/name}","comments_url":"https://api.github.com/repos/neilime/zf2-assets-bundle/issues/56/comments","events_url":"https://api.github.com/repos/neilime/zf2-assets-bundle/issues/56/events","html_url":"https://github.com/neilime/zf2-assets-bundle/issues/56","id":186735115,"number":56,"title":"Avoid 404 error on empty CSS generated","user":{"login":"wambaloo","id":15379206,"avatar_url":"https://avatars.githubusercontent.com/u/15379206?v=3","gravatar_id":"","url":"https://api.github.com/users/wambaloo","html_url":"https://github.com/wambaloo","followers_url":"https://api.github.com/users/wambaloo/followers","following_url":"https://api.github.com/users/wambaloo/following{/other_user}","gists_url":"https://api.github.com/users/wambaloo/gists{/gist_id}","starred_url":"https://api.github.com/users/wambaloo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wambaloo/subscriptions","organizations_url":"https://api.github.com/users/wambaloo/orgs","repos_url":"https://api.github.com/users/wambaloo/repos","events_url":"https://api.github.com/users/wambaloo/events{/privacy}","received_events_url":"https://api.github.com/users/wambaloo/received_events","type":"User","site_admin":false},"labels":[{"id":19392222,"url":"https://api.github.com/repos/neilime/zf2-assets-bundle/labels/bug","name":"bug","color":"fc2929","default":true}],"state":"open","locked":false,"assignee":{"login":"neilime","id":314088,"avatar_url":"https://avatars.githubusercontent.com/u/314088?v=3","gravatar_id":"","url":"https://api.github.com/users/neilime","html_url":"https://github.com/neilime","followers_url":"https://api.github.com/users/neilime/followers","following_url":"https://api.github.com/users/neilime/following{/other_user}","gists_url":"https://api.github.com/users/neilime/gists{/gist_id}","starred_url":"https://api.github.com/users/neilime/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neilime/subscriptions","organizations_url":"https://api.github.com/users/neilime/orgs","repos_url":"https://api.github.com/users/neilime/repos","events_url":"https://api.github.com/users/neilime/events{/privacy}","received_events_url":"https://api.github.com/users/neilime/received_events","type":"User","site_admin":false},"assignees":[{"login":"neilime","id":314088,"avatar_url":"https://avatars.githubusercontent.com/u/314088?v=3","gravatar_id":"","url":"https://api.github.com/users/neilime","html_url":"https://github.com/neilime","followers_url":"https://api.github.com/users/neilime/followers","following_url":"https://api.github.com/users/neilime/following{/other_user}","gists_url":"https://api.github.com/users/neilime/gists{/gist_id}","starred_url":"https://api.github.com/users/neilime/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neilime/subscriptions","organizations_url":"https://api.github.com/users/neilime/orgs","repos_url":"https://api.github.com/users/neilime/repos","events_url":"https://api.github.com/users/neilime/events{/privacy}","received_events_url":"https://api.github.com/users/neilime/received_events","type":"User","site_admin":false}],"milestone":null,"comments":2,"created_at":"2016-11-02T08:06:17Z","updated_at":"2016-11-04T08:03:33Z","closed_at":null,"body":"Hi !!!\r\n\r\nI was looking for optimize my application on page loading, and I notice that an empty CSS file is already generated by assets-bundle plugin. This file (named like dev_0fead24561256adfebb64c5614a.css) is already empty and made page loading in Chrome and Firefox very long (because these browser send a 404 error when trying to load an empty CSS file).\r\nSo I look into the source code to see how I can speed up my app by avoid this empty loading.\r\nI modify the following lines to optimize that, I let you see if it's the right way to do that or if I missed something. I think it could be a plus to integrate this case in your library to not generate an empty file and not include it in page loading.\r\n\r\nIn file AssetsBundle/AssetFile/AssetFilesCacheManager.php, line 184 to the end of the method, I replaced that:\r\n```php\r\nelse {\r\n    \\Zend\\Stdlib\\ErrorHandler::start();\r\n    $sAssetFilePath = $oAssetFile->getAssetFilePath();\r\n    if (!is_file($sAssetFilePath)) {\r\n        throw new \\LogicException('Asset file \"' . $sAssetFilePath . '\" does not exits');\r\n    }\r\n    copy($sAssetFilePath, $sCacheFilePath);\r\n    \\Zend\\Stdlib\\ErrorHandler::stop(true);\r\n}\r\nreturn $oAssetFile->setAssetFilePath($sCacheFilePath);\r\n```\r\n\r\nby: \r\n```php\r\nelse {\r\n    \\Zend\\Stdlib\\ErrorHandler::start();\r\n    $sAssetFilePath = $oAssetFile->getAssetFilePath();\r\n    if (!is_file($sAssetFilePath)) {\r\n        throw new \\LogicException('Asset file \"' . $sAssetFilePath . '\" does not exits');\r\n    }\r\n    /* ADD TO AVOID 404 LOADING DUE TO EMPTY CSS FILE */\r\n    $size = filesize($sAssetFilePath);\r\n    if ($size > 0) {\r\n        copy($sAssetFilePath, $sCacheFilePath);\r\n    } else {\r\n        $oAssetFile = null;\r\n    }\r\n    \\Zend\\Stdlib\\ErrorHandler::stop(true);\r\n}\r\nreturn (null !== $oAssetFile ? $oAssetFile->setAssetFilePath($sCacheFilePath) : null);\r\n```\r\n\r\nAnd in file AssetBundle/AssetFile/AssetFilesManager.php, line 212, I replaced:\r\n```php\r\nreturn array($this->getAssetFilesCacheManager()->cacheAssetFile($oTmpAssetFile)->setAssetFileType(\\AssetsBundle\\AssetFile\\AssetFile::ASSET_CSS));\r\n```\r\n\r\nby:\r\n```php\r\n$cache = $this->getAssetFilesCacheManager()->cacheAssetFile($oTmpAssetFile);\r\n$result = (null !== $cache) ? [$cache->setAssetFileType(\\AssetsBundle\\AssetFile\\AssetFile::ASSET_CSS)] : [];\r\nreturn $result;\r\n```\r\n\r\nI hope it will help !"},"comment":{"url":"https://api.github.com/repos/neilime/zf2-assets-bundle/issues/comments/258366336","html_url":"https://github.com/neilime/zf2-assets-bundle/issues/56#issuecomment-258366336","issue_url":"https://api.github.com/repos/neilime/zf2-assets-bundle/issues/56","id":258366336,"user":{"login":"wambaloo","id":15379206,"avatar_url":"https://avatars.githubusercontent.com/u/15379206?v=3","gravatar_id":"","url":"https://api.github.com/users/wambaloo","html_url":"https://github.com/wambaloo","followers_url":"https://api.github.com/users/wambaloo/followers","following_url":"https://api.github.com/users/wambaloo/following{/other_user}","gists_url":"https://api.github.com/users/wambaloo/gists{/gist_id}","starred_url":"https://api.github.com/users/wambaloo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wambaloo/subscriptions","organizations_url":"https://api.github.com/users/wambaloo/orgs","repos_url":"https://api.github.com/users/wambaloo/repos","events_url":"https://api.github.com/users/wambaloo/events{/privacy}","received_events_url":"https://api.github.com/users/wambaloo/received_events","type":"User","site_admin":false},"created_at":"2016-11-04T08:03:33Z","updated_at":"2016-11-04T08:03:33Z","body":"Hi !\r\n\r\nI could do it when my internet access will be open for windows command line in my job... proxy bloqued it so I can't clone the git repository and I can't commit... I hope I could do it soon !"}}
{"actor":{"display_login":"wambaloo"}}