Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

The assets in In-Portal are managed by "<inp2:m_Compress .../>" tag (see INP-382 - Getting issue details... STATUS ). It works like this:

  1. create some assets "*.js" or ".css" files
  2. instead of referencing assets directly specify their relative path in "m_Compress" tag
<script type="text/javascript" src="<inp2:m_Compress files='js/script.js|js/calendar/calendar-setup.js'/>"></script>
<link rel="stylesheet" href="<inp2:m_Compress files='js/jquery/thickbox/thickbox.css|js/calendar/calendar-blue.css'/>" type="text/css" media="screen"/>

Asset building process differs radically for website visitors and developers:

 For Regular VisitorsFor Developers
1only, when combined asset is missingwhen any of assets is changed
2combine all specified assets into single file
3compress result using "CSS/JS Compression Engine" setting 
4store result in "/system/cache" path
5return URL to asset like "/system/cache/asset_name?ts=timestamp"

There are several issues, that can happen:

  • developers can't see if any compression errors were present for regular visitors (because their asset version isn't compressed to allow debugging)
  • if compression error happens, then combined asset would be empty with no indication about the fact, that compression error happened

When the need for asset management araised in 2010 there was no alternatives on the market (the https://github.com/kriswallsmith/assetic was developed in 2011) and we had to write something ourselves. This unfortunately forced us to copy/paste specific (latest at the time) versions of "JsMin" and "CssMin" into In-Portal. As a result we're not receiving any updates/fixes from these libraries as well.

Fixtures

VALID

Non-Minified File
@media screen and (min-width: 480px) and (max-width: 639px) {
	body {
		background: #000 url(/themes/advanced/img/header-bg.png) no-repeat top left;
	}
}

@media screen and (max-width: 640px) {
	body {
		background: #000 url(/themes/advanced/img/header-bg.png) no-repeat top left;
	}
} 

INVALID

Compressed File Using YUICompressor
@media screen and(min-width:480px) and(max-width:639px){body{background:#000 url(/themes/advanced/img/header-bg.png) no-repeat top left;}}@media screen and(max-width:640px){body{background:#000 url(/themes/advanced/img/header-bg.png) no-repeat top left;}}

VALID

Minified using PHPMin
@media screen and (min-width: 480px) and (max-width: 639px){body{background:#000 url(/themes/advanced/img/header-bg.png) no-repeat top left}}@media screen and (max-width: 640px){body{background:#000 url(/themes/advanced/img/header-bg.png) no-repeat top left}}

Turns out that YUICompressor is awfully bad in compression of CSS, that uses media queries, because it transforms "and (" into "and(" and that immediately makes CSS non-working.

Solution

  1. use https://github.com/kriswallsmith/assetic library for asset file creation (internals of "m_Compress" tag)
  2. use JsMin and CssMin from Composer
  3. deprecate "JsMinifyHelper" and "CssMinifyHelper" classes in favor of "MinifyHelper::compressString" method
  4. store compiled assets in "/system/cache/assets/" folder instead of "/system/cache/" folder

Related Discussions

Related Tasks

INP-1687 - Getting issue details... STATUS

  • No labels