protected function optimizeUrls($content, $file)
    {
        preg_match_all('/url\((.[^\)]*)\)/is', $content, $matches, PREG_SET_ORDER);

        foreach ($matches as $match) {
            $uri = $match[1];

            // Remove the apostrophs
            if (strpos($uri, '\'') === 0 || strpos($uri, '"') === 0) {
                $uri = substr($uri, 1, -1);
            }
            
            // If the uri is an absolute url we do not change anything
            if (strpos($uri, 'http') === 0) {
                continue;
            }
            
            $additionalData = $this->getAdditionalUriData($uri);
            $uri = $this->removeAdditionalUriData($uri);

            $path = dirname($file);
            $fullFilePath = realpath($path . '/' . $uri);
            $fileInformation = pathinfo($fullFilePath);
            
            $imageExtensions = array('png', 'jpg', 'jpeg', 'gif');

            if (in_array($fileInformation['extension'], $imageExtensions)) {
                // Load the file content
                $fileContent = $this->fileBackend->loadFromFile($fullFilePath);
                
                // Encode the file content
                $encodedContent = base64_encode($fileContent);
                $urlData = 'data:image/gif;base64,' . $encodedContent;
                
                // Replace the reference in the css content
                $content = str_replace($match[1], '\'' . $urlData . '\'', $content);
            } else {
                $type = AssetManager::BINARY;
                
                // Cache the file
                $cachedFile = $this->assetCacheManager->generateCachedFile($type, $fullFilePath);
                $url = $this->assetCacheManager->getUrlToTheAssetLoader($cachedFile['file']);
    
                // Add the additional data
                if ($additionalData !== '') {
                    $url .= $additionalData;
                }

                // Replace the reference in the css content
                $content = str_replace($match[1], '\'' . $url . '\'', $content);
            }
        }

        return $content;
    }