{"action":"created","issue":{"url":"https://api.github.com/repos/phalcon/cphalcon/issues/925","repository_url":"https://api.github.com/repos/phalcon/cphalcon","labels_url":"https://api.github.com/repos/phalcon/cphalcon/issues/925/labels{/name}","comments_url":"https://api.github.com/repos/phalcon/cphalcon/issues/925/comments","events_url":"https://api.github.com/repos/phalcon/cphalcon/issues/925/events","html_url":"https://github.com/phalcon/cphalcon/issues/925","id":17200168,"number":925,"title":"[NFR] Make assets manager recompile files only if needed","user":{"login":"Swader","id":1430603,"avatar_url":"https://avatars.githubusercontent.com/u/1430603?v=3","gravatar_id":"","url":"https://api.github.com/users/Swader","html_url":"https://github.com/Swader","followers_url":"https://api.github.com/users/Swader/followers","following_url":"https://api.github.com/users/Swader/following{/other_user}","gists_url":"https://api.github.com/users/Swader/gists{/gist_id}","starred_url":"https://api.github.com/users/Swader/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Swader/subscriptions","organizations_url":"https://api.github.com/users/Swader/orgs","repos_url":"https://api.github.com/users/Swader/repos","events_url":"https://api.github.com/users/Swader/events{/privacy}","received_events_url":"https://api.github.com/users/Swader/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/phalcon/cphalcon/labels/New%20Feature%20Request","name":"New Feature Request","color":"0052cc"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":11,"created_at":"2013-07-25T08:51:06Z","updated_at":"2016-06-03T11:28:01Z","closed_at":null,"body":"Currently, the assets manager recompiles all the added assets on every request. This might get inefficient with a lot of resources.\r\n\r\nI suggest the following approach which I've personally been using for a while now in my own asset manager:\r\n\r\nRequest 1:\r\nRead filemtime of all files.\r\nGenerate hash from all these times.\r\nAppend hash to output file name.\r\nCheck if file already exists. It doesn't.\r\nCompress and minify, serve file.\r\n\r\nRequest 2 (if no files have changed):\r\nRead filemtime of all files.\r\nGenerate hash from times, append to output file name.\r\nCheck if file exists. It does - no recompile needed.\r\nOutput existing file.\r\n\r\nRequest 2 (some changes were done - either new file added, or file changed):\r\nRead filemtime of all files.\r\nAppend times hash to output file.\r\nCheck if file exists - it doesn't because hash is different.\r\nRecompile and serve file.\r\n\r\nAside from eliminating overhead from recompiling on every request, this also has the side benefit of making sure your clients ALWAYS have the most up to date JS and CSS loaded, because when changes occur the file name is different and cannot be stuck in the browser's cache.\r\n\r\n<bountysource-plugin>\r\n---\r\nWant to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/1896273-nfr-make-assets-manager-recompile-files-only-if-needed?utm_campaign=plugin&utm_content=tracker%2F50707&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F50707&utm_medium=issues&utm_source=github).\r\n</bountysource-plugin>"},"comment":{"url":"https://api.github.com/repos/phalcon/cphalcon/issues/comments/223555542","html_url":"https://github.com/phalcon/cphalcon/issues/925#issuecomment-223555542","issue_url":"https://api.github.com/repos/phalcon/cphalcon/issues/925","id":223555542,"user":{"login":"mzf","id":4039372,"avatar_url":"https://avatars.githubusercontent.com/u/4039372?v=3","gravatar_id":"","url":"https://api.github.com/users/mzf","html_url":"https://github.com/mzf","followers_url":"https://api.github.com/users/mzf/followers","following_url":"https://api.github.com/users/mzf/following{/other_user}","gists_url":"https://api.github.com/users/mzf/gists{/gist_id}","starred_url":"https://api.github.com/users/mzf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mzf/subscriptions","organizations_url":"https://api.github.com/users/mzf/orgs","repos_url":"https://api.github.com/users/mzf/repos","events_url":"https://api.github.com/users/mzf/events{/privacy}","received_events_url":"https://api.github.com/users/mzf/received_events","type":"User","site_admin":false},"created_at":"2016-06-03T11:28:01Z","updated_at":"2016-06-03T11:28:01Z","body":"good idea +1"}}
{"actor":{"display_login":"mzf"}}